User.Identity.IsAuthenticated always false in .net core custom authentication

前端 未结 4 1439
無奈伤痛
無奈伤痛 2020-12-30 04:25

Can anyone please check below code and let me know why I\'m getting always false (User.Identity.IsAuthenticated)??. I\'m getting cookie on my browser properly and able to

相关标签:
4条回答
  • 2020-12-30 04:42

    You can try this one. I think this can help

    var userIdentity = new ClaimsIdentity( claims, AuthenticationTypes.Basic);

    0 讨论(0)
  • 2020-12-30 04:47

    ClaimsIdentity.IsAuthenticated returns false when ClaimsIdentity.AuthenticationType is null or empty. To avoid that, stop using the parameterless ClaimsIdentity constructor and use the overload accepting an authenticationType parameter:

    var userIdentity = new ClaimsIdentity("Custom");
    
    0 讨论(0)
  • 2020-12-30 04:56

    In my case the problem was in the startup file. app.UseAuthentication() line was coming after app.UseMvc() line.I reversed the orders and it started to work.

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

    I know this question was asked a long time ago, but it might be useful to another person.

    Using app.UseAuthentication(); right before app.UseAuthorization(); inside the Configure method in the Startup.cs class fixed it for me.

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