Unable to add and fetch custom claims values

后端 未结 3 1377
广开言路
广开言路 2021-01-07 17:48

I am using mvc 5 with identity 2.0. I want use custom claim values over the application but I get null values. What am I doing wrong?

Updated code<

相关标签:
3条回答
  • 2021-01-07 17:55

    You should add those claims on identity validation phase. Please check similar implementation here: Server side claims caching with Owin Authentication

    0 讨论(0)
  • 2021-01-07 18:09

    In your account controller, to get a valid authenticationManager, you should use Request.GetOwinContext().Authentication. Im affraid System.Web.HttpContext.Current.GetOwinContext().Authentication gets you a fresh authenticationManager instead of the current Owin context one

    0 讨论(0)
  • 2021-01-07 18:14

    First you need to convert identity to claims identity and then try to get claim using identity type

    (HttpContext.Current?.User?.Identity as ClaimsIdentity)?.Claims?.FirstOrDefault(x => x.Type == "urn:Custom:MasterUniqueId")?.Value
    
    0 讨论(0)
提交回复
热议问题