Replace default IPrincipal object in ASNET

There is an easy way to override or provide IPrincipal object exposed by the System.Web.UI.Page.User property. Implement OnAuthenticate handler in the Global.asax

public void WindowsAuthentication_OnAuthenticate(Object Source, WindowsAuthenticationEventArgs e) {
    e.User = new GenericPrincipal(e.Identity, new string[] {"Role1", "Role2", "Role3"});
}

This way you do not have to implement RoleProvider class, just set desired roles on the user based on e.Identity.

Leave a Reply

Back to Top