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

后端 未结 5 1754
野趣味
野趣味 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:24

    ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType);
    identity.AddClaim(new Claim(ClaimTypes.Name, userName));
    identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, UserID));
    

    ClaimTypes.NameIdentifier is the claim for the function User.Identity.GetUserId()

提交回复
热议问题