Request.IsAuthenticated is always false

前端 未结 10 2130
迷失自我
迷失自我 2020-12-15 04:34

Can you tell me why FormsAuthentication.SetAuthCookie(user.Name, false); is not causing Request.IsAuthenticated to be true?

Here is my code

相关标签:
10条回答
  • 2020-12-15 05:22

    In my case, it was a problem in Chrome browser. I just removed all cookies stored and works.

    0 讨论(0)
  • 2020-12-15 05:26

    I had exactly same problem in my MVC4 Web Application. One more possible reason for this problem is below method in IdentityModels.cs file

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
                                // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
                                var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
                                // Add custom user claims here
                       return userIdentity;
        }
    

    Make sure DefaultAuthenticationTypes is ApplicationCookie

    Cheers,

    0 讨论(0)
  • 2020-12-15 05:30

    I had the same problem in an MVC5 project. The solution was to add the following lines to the modules section in the system.webServer

    <remove name="FormsAuthentication" />
    <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
    
    0 讨论(0)
  • 2020-12-15 05:31

    In my case I had this issue which ended up in a redirect-loop where the user would be redirected to the login, successfully logged in and then back to our site but since Request.IsAuthenticated was false the user was redirected to the login agan.

    In our case this was solved by using another CookieManager,

    var cookieOptions = new CookieAuthenticationOptions();
    cookieOptions.CookieManager = new SystemWebCookieManager(); 
    app.UseCookieAuthentication(cookieOptions);
    

    Turns out that there was some kind of bug in Katana that this other CookieManager worked around, in out case this solved the issue.

    https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues

    0 讨论(0)
提交回复
热议问题