title: Sign in as different user in ASP.MVC is not changing user identity
body: <p>I'm developing an MVC web application using the Windows authentication. The aim is to allow automated logging when the page is opened but allow signing as different user on demand. I'm trying to use the code from here <a href="https://stackoverflow.com/questions/17871816/login-as-another-user-mvc-4-windows-authentication">&#39;Login as another user&#39; MVC 4 Windows Authentication</a> and here <a href="http://www.roelvanlisdonk.nl/?p=825" rel="nofollow noreferrer">http://www.roelvanlisdonk.nl/?p=825</a> but none of them is working for me.</p>
  
  <p>I've simplified the case to the maximum, so it looks as follows:</p>
  
  <pre><code>public string Logout()
  {
      AuthenticationAttempts = AuthenticationAttempts + 1;
      if (AuthenticationAttempts == 1)
      {
          this.Send401();
      }
      var domain = User.Identity.Name.Split('\\')[0];
      var user = User.Identity.Name.Split('\\')[1];
      return string.Format("Domain: {0}&lt;br&gt;User: {1}", domain, user);
  }
  
  /// &lt;summary&gt;
  /// Send a 401 response
  /// &lt;/summary&gt;
  public void Send401()
  {
      // Create a 401 response, the browser will show the log-in dialogbox, asking the user to supply new credentials, 
      // if browser is not set to "automaticaly sign in with current credentials"
      Response.Buffer = true;
      Response.StatusCode = 401;
      Response.StatusDescription = "Unauthorized";
  
      // A authentication header must be supplied. This header can be changed to Negotiate when using keberos authentication
      Response.AddHeader("WWW-Authenticate", "NTLM");
  
      // Send the 401 response
      Response.End();
  }
  
  private int _authenticationAttempts = 0;
  public int AuthenticationAttempts
  {
      get
      {
          if (!string.IsNullOrEmpty(string.Format("{0}", Session["AuthenticationAttempts"])))
          {
              int.TryParse(Session["AuthenticationAttempts"].ToString(), out _authenticationAttempts);
          }
  
          return _authenticationAttempts;
      }
      set
      {
          _authenticationAttempts = value;
          Session["AuthenticationAttempts"] = _authenticationAttempts;
      }
  }
  </code></pre>
  
  <p>When I call Logout action method for the first time I'm getting the sign in window, but when I click okay the User.Identity is still as it was.</p>
  
  <p>EDIT:</p>
  
  <p>I found that</p>
  
  <pre><code>Request.ServerVariables["LOGON_USER"]
  </code></pre>
  
  <p>stores newly logged user identity, but why User.Identity isn't changing?</p>