I had the same question when I applied a custom membership provider for MVC. I ended up doing two things. I store the user ID in the ProviderUserKey
field of the MembershipUser
object. See provideruserkey . Then, to answer your question, yes, I created a custom principle from System.Web.Security.IPrincipal, although I later inherited from System.Web.Security.RolePrincipal
because I need role support.
public class MyPrincipal : RolePrincipal { public Guid Id { get; set; } public MyPrincipal(string providerName, IIdentity identity, Guid id) : base(identity) { Id = id; } }
Update: The reason I don't want to use the session in my case is because I disabled it for the application. I read that the main concept of MVC is the separation of problems, and this is closely related to how a website that is stateless works. Although I canβt remember where I read it now, when I try to remember. However, I also remember that if you can eliminate the session, you must do it. This will allow IIS to serve concurrent requests from your application, rather than waiting for one request to complete (and free a user session) before the next request can use the session and send its response. The biggest impact on this is loading page content using Ajax.
source share