title: ASP.NET MVC Not logged in after successfully signed in
body: <p>In my own machine and browser (chrome), I am not able to login in my website. It works in other browsers, with other users of chrome and in incognito window.
  It also works in my development environment or in other stages of the same website.</p>
  
  <p>My relevant code regarding login is the following:</p>
  
  <p>=> StartUp.ConfigureAuth</p>
  
  <pre><code>app.UseCookieAuthentication(new CookieAuthenticationOptions
  {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login"),
      Provider = new CookieAuthenticationProvider
      {
          OnValidateIdentity = SecurityStampValidator.OnValidateIdentity&lt;ApplicationUserManager, Data.DbContainer.Entities.User&gt;(
              validateInterval: TimeSpan.FromMinutes(30),
              regenerateIdentity: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager))
      }
  });            
  app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
  app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  </code></pre>
  
  <p>=> Login endpoint</p>
  
  <pre><code>[HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
  {
      if (!ModelState.IsValid)
      {
          return View(model);
      }
  
      SignInStatus result;
      using (var mainDb = MainDbDataManager.GetInstance())
      {
          var user = await mainDb.UserManager.FindByNameAsync(model.Username);
          // Check if user has permission to access CMS
          if (user != null &amp;&amp; !await mainDb.UserManager.IsInAnyRoleAsync(user.Id, Customer.RoleName, Administrator.RoleName))
          {
              result = SignInStatus.Failure;
          }
          else
          {
              using (var signInManager = HttpContext.GetOwinContext().Get&lt;ApplicationSignInManager&gt;())
              {
                  result = await signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, shouldLockout: false);
              }
          }
  
          switch (result)
          {
              case SignInStatus.Success:
                  {
                      // Set user's language
                      Session[Core.Helpers.ConstantsHelper.SessionConstants.LanguageCodeKey] = user.Language.Code;
  
                      return RedirectToLocal(returnUrl);
                  }
              case SignInStatus.LockedOut:
                  ModelState.AddModelError("", Strings.LoginDisabledError);
                  return View(model);
              case SignInStatus.Failure:
              default:
                  ModelState.AddModelError("", Strings.LoginFailedError);
                  return View(model);
          }
      }
  }
  </code></pre>
  
  <p>I debugged the login endpoint and I noticed that the sign in is successful, but the User.Identity.Username is null, as long as Request.IsAuthenticated in my next endpoint is false.</p>
  
  <p>I checked already <a href="https://stackoverflow.com/questions/20737578/asp-net-sessionid-owin-cookies-do-not-send-to-browser">this</a>, but I could not find a successful solution.</p>
  
  <p>I tried the following:</p>
  
  <ul>
  <li>Adding <code>Session["Workaround"] = 0;</code> to <code>Session_Start()</code>, as mentioned in the previous link. I am not sure this is the correct place, but it seems so.</li>
  <li>Applying <code>SystemWebCookieManager</code>, as mentioned in the previous link.</li>
  <li>Removing the cookies of the browser</li>
  <li>Restarting the browser</li>
  <li>Calling <code>AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);</code>, even though there is no logged user.</li>
  </ul>
  
  <p>I really do not know whether this is a browser problem or a development problem.</p>
  
  <p>Could anyone find a solution or a workaround?</p>