Access/use the same object during a request - asp.net -


"itemprop =" text ">

I have an HttpModule that creates a CommunityPrincipal (apply the IPrincipal interface) on every request object. I want to store the object for every request whenever I do it without needing to cast it or need to re-create it anyway so i can get it.

Actually I want to copy the FormsAuthenticationModule that works. This HttpContext.User property is an object that implements the IPrincipal interface, provides on every request

I would like to be able to call HttpContext.MySpecialUser etc for some way. (Or MySpecialContext.MySpecialUser - create stable classes) that will return my object (specific type).

I can use an extension method but I do not know how to store the object so that it can be reached during the request.

How can it be obtained?

Please note that I want to store it in a specific form (Community Principal - not just an object) it should definitely be available only for the current request being processed And not shared with all other threads / requests.

Right now I have assigned my CommunityPrincipal object to HttpContext.User in HttpModule, but it requires me to have a cast every one I need to use properties on the CommunityPrincipal object which is not defined in the IPrincipal interface What is the plan.

Text after "itemprop =" text ">

Assign your custom principal to the reference. The user is right. Hope you are doing it in Application_AuthenticateRequest.

For your question, do you only use user objects from ASPX pages? Then you can apply the custom base page that includes cast for you

  public class CommunityBasePage:. Page {new CommunityPrincipal user {{get back as base.User CommunityPrincipal; }}  

Then get your pages from CommunityBasePage and you will be able to get all your properties from this.User . >.


Comments