I have separate project with some of my custom ASP.NET MVC helpers
In one of my helpers I need to check user identity.
How may I get User.Identity
working there?
By default it is living in System.Security.Principal
in interface called interface IPrincipal
More easily you may access it by:
HttpContext.Current.User.Identity
So the HttpContext.Current is the trick.
The HtmlHelper has the current ViewContext and via HttpContext you'll get the User object for the current User. In your extension Method you can use this
public static bool MyHelper(HtmlHelper helper)
{
var userIdentity = helper.ViewContext.HttpContext.User.Identity;
// more code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With