I’m told that if I want to grab a claim within a controller I can do something like:
IClaimsIdentity u = (IClaimsIdentity) 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
HttpContextand use the User property of the controller directly: