I'm told that if I want to grab a claim within a controller I can do something like:
IClaimsIdentity u = (IClaimsIdenti开发者_如何学Goty) this.HttpContext.User.Identity;
var ni = u.Claims.First(x => x.ClaimType == ClaimTypes.NameIdentifier).Value;
however, this violates the separation between views and controllers. the controller may be called in a context where there is no HttpContext
- so what is the proper way to do it?
TIA - ekkis
Just leave out the HttpContext
and use the User property of the controller directly:
var u = (IClaimsIdentity)this.User.Identity;
精彩评论