I\'ve written a custom principal object which contains a few additional fields (email and userid in addition to the username).
In order to access these properties I have
The best way to make your IPrincipal
implementation accessible in your Razor pages using ASP.NET MVC, is doing the following:
System.Security.Principal.IPrincipal
interface.System.Security.Principal.IIdentity
interface.Global.asax
define a method for: void Application_AuthenticateRequest(Object, EventArgs)
that persists your both implementations of IPrincipal
and IIdentity
.IPrincipal
to expose your implementation of IIdentity
.
.At the end, you will be able to access your custom implementation of IIdentity
instead of type casting. You now can access your custom implementation like this:
Hello @User.CustomIdentity().FirstName @User.CustomerIdentity().LastName!
These steps are a concise and brief description of a well detailed article written here: http://rizzo7.blogspot.com/2012/04/mvc-30-razor-custom-principal-and.html