Request.IsAuthenticated is always false

前端 未结 10 2159
迷失自我
迷失自我 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: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 GenerateUserIdentityAsync(UserManager 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,

提交回复
热议问题