Browsed by
Tag: User

ASP.NET MVC – Set custom IIdentity or IPrincipal

ASP.NET MVC – Set custom IIdentity or IPrincipal

Source I decided to use IPrincipal instead of IIdentity because it means I don’t have to implement both IIdentity and IPrincipal. Create the interface

CustomPrincipal

  CustomPrincipalSerializeModel – for serializing custom information into userdata field in FormsAuthenticationTicket object.

  LogIn method – setting up a cookie with custom information

  Global.asax.cs – Reading cookie and replacing HttpContext.User object, this is done by overriding PostAuthenticateRequest

  Access in Razor views

    and in code:…

Read More Read More