User.Identity.IsAuthenticated is false after successful login

user.identity.isauthenticated how it works
user.identity.isauthenticated always false .net core
user.identity.isauthenticated always false mvc
httpcontext.current.user.identity.isauthenticated always false windows authentication
how to set user.identity.isauthenticated to true
user identity isauthenticated is false asp net core
httpcontext.user.identity.isauthenticated always false mvc
user.identity.isauthenticated always false web api

I need to get the UserId Guid directly after a successful login. The following code doesn't work:

if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value))
    FormsAuthentication.SetAuthCookie(txtUsername.Value, true);

    if (HttpContext.Current.User.Identity.IsAuthenticated)
        // doesn't run
        Guid puk = (Guid)Membership.GetUser().ProviderUserKey;            

The following code does work:

if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value))
    FormsAuthentication.SetAuthCookie(txtUsername.Value, true);

    MembershipUser user = Membership.GetUser(txtUsername.Value);

    if (user != null)
        Guid puk = (Guid)user.ProviderUserKey;

Why does this happen? Is there something more to do besides SetAuthCookie?

Because when you call FormsAuthentication.SetAuthCookie(txtUsername.Value, true); you store the key on the client's cookies. For this you need to do a response to the user. And for HttpContext.Current.User.Identity to be filled with cookie you need one more request.

In short your scheme looks like this:

  1. Client sends his UserName and Password.

  2. Server gets and checks it. If they are valid the server sends Set-Cookie header to the client.

  3. Client receives and stores it. For each request client sends cookies back to the server.

UPDATE for @Jake

Adding an example of setting User in HttpContext

var identity = new System.Security.Principal.GenericIdentity(user.UserName);
var principal = new GenericPrincipal(identity, new string[0]);
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;  

Note that you could create your custom principal class inheriting from GenericPrincipal or ClaimsPrincipal

Context.User.Identity.isAuthenticated is false after successfully login , Hello, I have implemented a simple identity server in core 2.1 application. after local login, the page keeps redirecting to login page� "HttpContext.Current.User.Identity.IsAuthenticated" is false after successfully login on IE version only. The code was working before but suddenly it is not working on IE on testing server only. On chrome and firefox its working. I moved the code on production and integration server, and it is working properly on other server's.

I had the same problem too. I forgot to set the web.config configuration.

Maybe you missed too.

    <authentication mode="Forms">
      <forms loginUrl="~/user/login" timeout="1000" name="__Auth" />

HttpContext.User.Identity.IsAuthenticated is false after successful , I have a try catch around the login method so it does successfully sign in. I really dont understand why I am unable to access my identity that I just� Find answers to User Identity IsAuthenticated is false after a successful Login Validation 28063988/User-Identity-IsAuthenticated-is-false-after-a

In my development environment case, requireSSL property was set to true, I fixed the problem by changing it to requireSSL = false.

[Solved] Why User.Identity.IsAuthenticated always false , User.Identity.IsAuthenticated won't be set to true until the next request after calling FormsAuthentication.SetAuthCookie(). I have an webforms app that has a login screen. When I click the login button, the User.Identity.IsAuthenticated is always false on the first click. Here is the code for logging in: prot

I tried all the above solutions ,but the thing that solves my problem was commenting this in web.config

  <remove name="FormsAuthentication"/>

User.Identity.IsAuthenticated remains false. why?, i have login page with login user control. BUT i'm NOT using membership API, instead im using custom authentication. After authenticating user� Possible duplicate of User.Identity.IsAuthenticated is false after successful login – gmiley Jan 13 '16 at 23:53 see my duplicate update above. i can't use setauthcookie – cdub Jan 14 '16 at 0:00

IsAuthenticated always false after successful login - Questions, IsAuthenticated always false after successful login public IActionResult Login() { if (!HttpContext.User.Identity.IsAuthenticated) { return� User.Identity.IsAuthenticated always false in .net core custom authentication 1 User.Identity.IsAuthenticated always returns false even after successfully logged in using PasswordSignInAsync in core 2.2

ASP.NET Core IsAuthenticated is always false after successful login , Hi okta support, I have an ASP.NET Core application which uses OpenId Connect for user authentication. After browser redirect to the OKTA� User.Identity.IsAuthenticated always return false so userid comes always -1, I am not even able to short out my mistake, what mistake am doing and how can i overcome with this, please help me.. Posted 10-Feb-15 18:57pm

Request.IsAuthenticated is always false, httpcontext user identity isauthenticated always false mvc answers to User Identity IsAuthenticated is false after a successful Login Validation always false. I'm using the new .Net Core 2.0 Preview 2 along with Visual Studio Community 2017 15.3 preview. Ive been struggling with this for days, Im not sure if my code is wrong or if this is an actual bug.

  • Is there any way to access User Identity in the same request?
  • @AhmadAhmadi you can set it manually assigning CustomPrincipal object to User property of HttpContext.
  • @OleksiiAza Could you possibly update your answer to show how to do this?
  • This would remove forms authentication altogether, so of course that would let the user go by.
  • This didn't remove forms authentication but I'm not sure what it's doing. The true/false is now working with that module removed;... odd?