Storing extended value in HttpContext.Current.User (IPrinciple)

I created a class ExtendedId

that extends GenericIdentity

. (ID and name are stored here)

In the httpmodule, I have stored this extended id in Current.User, for example:

HttpContext.Current.User = new GenericPrincipal(myExtendedId, roles);

      

The problem is, how can I get my type again ExtendedId

?

If I try this:

ExtendedId eId = (ExtendedId)HttpContext.Current.User.Identity;

      

I am getting casting error. I have a feeling that I am doing something silly here with the casting, but this morning I am a little hazy.

+2


a source to share


2 answers


try

ExtendedId eId = (ExtendedId) ((GenericPrincipal) HttpContext.Current.User) .Identity;



or

ExtendedId eId = ((GenericPrincipal) HttpContext.Current.User). Identity as ExtendedId;

+2


a source


Actually, it turned out to be a stupid mistake. Casting to ExtendedId was not done in cases where HttpContext.Current.User.Identity was not already set to ExtendedId (GenericIdentity was standard). I added type checking to prevent this. Sorry for wasting time with people!



0


a source







All Articles