title: A way of properly handling HttpAntiForgeryException in MVC 4 application
body: <p>Here is the scenario:</p>
  
  <p>I have a login page, when user sign it it is redirected to home application page. Then user is using browser back button, and now he is on login page. He tries to login again but now an exception is thrown:</p>
  
  <blockquote>
    <p>HttpAntiForgeryException (0x80004005): The provided anti-forgery token was meant for user "", but the current user is "userName".</p>
  </blockquote>
  
  <p>I know this is related to caching. I disabled browser caching for login action using custom NoCache filter which sets all required headers - no-cache, no-store, must-revalidate, etc. But </p>
  
  <ul>
  <li>this is not working on all browsers</li>
  <li>especially Safari (mobile in most cases) totaly ignores such settings</li>
  </ul>
  
  <p>I will try to make hacks and force safari mobile to refresh, but this is not what I'm expecting.</p>
  
  <p>I would like to know if I can:</p>
  
  <ul>
  <li>handle exception without showing user any problem exists (totally transparent for user)</li>
  <li><strong>prevent this problem by replacing anti forgery token user name</strong> which will allow user login again without this exception, if my hacks related to browser caching will stop work in next versions of browsers.  </li>
  <li>I really would like not to rely on browser behavior, since each one behaves differently.</li>
  </ul>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>To make some clarification, I know how to handle errors in MVC. The problem is that this handling errors is not solving my problem at all. Basic idea of error handling is redirect to custom error page with nice message. But I want to prevent this error to happen, not to handle it in user visible way. By handle I mean catch make username replace or other suitable action then continue login.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I've added below solution which is working for me.</p>