ASP.NET (OWIN) Identity: How to get UserID from a Web API controller?

后端 未结 5 1756
野趣味
野趣味 2020-11-30 03:33

(Using VS2013 RTW, ASP.NET MVC5)

I\'ve seen lots of documentation on how to add properties to the ApplicationUser class (and table) when using ASP.NET identity. But

5条回答
  •  囚心锁ツ
    2020-11-30 04:11

    Tried @Mastenka answer and it gave me nothing. I checked ClaimsIdentity and there were claims type "UserName", so as a result, I get username by using "UserName" as ClaimsType. Hope someone will give more info about it. It looks strange that "ClaimTypes.NameIdentifier" had no effect. (ApiController, ASP MVC API)

    var userName = ((ClaimsIdentity)RequestContext.Principal.Identity).Claims.FirstOrDefault(cl => cl.Type == "UserName")?.Value;
    

提交回复
热议问题