hi
I'm trying to implement a custom forms authentication based on existing objects.
i have created the following classes classes:

[Serializable]
public class MyIdentity : IIdentity
{
    // my custom members and properties
}

[Serializable]
public class MyPrincipal : IPrincipal
{
    // my custom members and properties
}

i'm using the following code for my authentication:

identity = new MyIdentity("name");
principale = new MyPrincipal(identity, arrRoles);
HttpContext.Current.User = principale;

the problem is that after the page is redirected the following cast doesn't work

MyPrincipal user = (MyPrincipal)HttpContext.Current.User;

it throws a cast exception. what am i doing wrong here ?

i found my mistake.
i needed to deserialize my ticket in global.asax event
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.