title: Anti forgery token is meant for user "" but the current user is "username"
body: <p>I'm building a single page application and experiencing an issue with anti-forgery tokens.</p>
  
  <p>I know why the issue happens I just don't know how to fix it.</p>
  
  <p>I get the error when the following happens:</p>
  
  <ol>
  <li>Non-logged-in user loads a dialog (with a generated anti-forgery token)</li>
  <li>User closes dialog</li>
  <li>User logs in</li>
  <li>User opens the same dialog </li>
  <li>User submits form in dialog</li>
  </ol>
  
  <blockquote>
    <p>Anti forgery token is meant for user "" but the current user is
    "username"</p>
  </blockquote>
  
  <p>The reason this happens is because my application is 100% single-page, and when a user successfully logs in through an ajax post to <code>/Account/JsonLogin</code>, I simply switch out the current views with the "authenticated views" returned from the server but <strong>do not reload the page.</strong></p>
  
  <p>I know this is the reason because if I simple reload the page between steps 3 and 4, there is no error.</p>
  
  <p>So it seems that <code>@Html.AntiForgeryToken()</code> in the loaded form still returns a token for the old user until the page is reloaded.</p>
  
  <p><strong>How can I change <code>@Html.AntiForgeryToken()</code> to return a token for the new, authenticated user?</strong></p>
  
  <p>I inject a new <code>GenericalPrincipal</code> with a custom <code>IIdentity</code> on every <code>Application_AuthenticateRequest</code> so by the time <code>@Html.AntiForgeryToken()</code> gets called <code>HttpContext.Current.User.Identity</code> is, in fact my custom Identity with <code>IsAuthenticated</code> property set to true and yet <code>@Html.AntiForgeryToken</code> still seems to render a token for the old user unless I do a page reload.</p>