Retain value in HttpModule RRS feed

  • Question

  • User-595641371 posted

    I've written custom httpmodule and it's being called up for every request. I want to store the value on my first request and this value needs to be retrieved for subsequent request. Is this possible in HttpModule?
    I know HttpContext.Current.Items preserve the value only for single request and we cannot use Session in our project as per our requirements.
    Do we have any other option apart from session\HttpContext.Current.Items for storing values in HttpModule?

    Wednesday, March 11, 2015 10:30 PM

All replies

  • User-1818759697 posted


    For this situation, you can share information throughout your application by using the HttpApplicationState class, most commonly accessed through the Application property of the HttpContext object. This class exposes a key-value dictionary of objects that you can use to store both .NET Framework objects and scalar values related to multiple Web requests from multiple clients.

    An instance of the HttpApplicationState class is created the first time any client requests a URL resource from within the virtual directory namespace of a particular ASP.NET application. This is the case for each Web application that is stored on the computer. Access to this per-application instance is provided through an HttpContext property named Application. All HttpModules and HttpHandlers, such as an ASP.NET page, have access to an instance of the context and therefore have access to the Application property during a given Web request.

    For more information, you could refer to:



    Thursday, March 12, 2015 9:50 PM
  • User-595641371 posted

    I understand HttpApplicationState is based on single user session and anyone can read and make update with in application boundary. But my requirement is some what different as per the behavior of HttpApplicationState.

    I've written PostAuthenticateRequest event in my HttpModule and it's getting called up for each request.

    context.PostAuthenticateRequest += new EventHandler(this.application_PostAuthenticateRequest);

    My plan here is,  On very first request, I need to identify authentication type (AD\FBA) of my web application and it needs to be stored either session\cookies. So that, on sub sequent request authentication type will be retrieved from session\cookies instead of checking the authentication type for every web request.

    Could you please help me to achieve above request instead of checking authentication type for every request?

    Friday, March 13, 2015 2:05 AM