开发者

Retrieving claims from a controller - how?

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜