Asp.net: Replace GenericPrincipal

Posted by Pickels on Stack Overflow See other posts from Stack Overflow or by Pickels
Published on 2010-05-04T17:41:54Z Indexed on 2010/05/04 17:48 UTC
Read the original article Hit count: 595

Hello,

I was wondering what the best way is to replace the genericPrincipal with my own CustomGenericPrincipal.

At the moment I have something like this but I aint sure if it's correct.

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
    HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
    if (authCookie != null)
    {
        FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
        var identity = new CustomIdentity(authTicket);
        var principal = new CustomPrincipal(identity);

        Context.User = principal;
    }
    else
    {
        //Todo: check if this is correct
        var genericIdentity = new CustomGenericIdentity();
        Context.User = new CustomPrincipal(genericIdentity);
    }
}

I need to replace it because I need a Principal that implements my ICustomPrincipal interface because I am doing the following with Ninject:

Bind<ICustomPrincipal>().ToMethod(x => (ICustomPrincipal)HttpContext.Current.User)
                        .InRequestScope();

So what's the best way to replace the GenericPrincipal?

Thanks in advance,

Pickels

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc