Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ASP.NET Session State in an HttpHandler?

I have an HttpHandler that is run on a client page (cross domain, not on our IIS server, etc) and when they click on our embedded link it fires off the Handler on our server. So far everything is working normally.

I am now trying to use the System.Web.HttpContext.Session object but it is null. I am thinking it is null because we don't have a session until our HttpHandler is invoked? And multiple calls to the handler will create a new session per call? If this is the case did MS just disable the Session object when calling into a HttpHandler? Can anyone confirm this?

If this is the case, what do you do to maintain state between calls? Some sort of SQL based data object? A file?

TIA

like image 276
Keith Barrows Avatar asked Jul 09 '09 22:07

Keith Barrows


People also ask

How do you use session state?

You can also configure session state by using the EnableSessionState value in the @ Page directive. The sessionState element enables you to specify the following options: The mode in which the session will store data. The way in which session identifier values are sent between the client and the server.

What is session state mode InProc?

InProc mode, which stores session state in memory on the Web server. This is the default. StateServer mode, which stores session state in a separate process called the ASP.NET state service.

What is an HTTP handler in ASP.NET Why and how is it used?

An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes . aspx files. When users request an .


1 Answers

Have your HttpHandler implement the IRequiresSessionState interface. It will enable session state use. IRequiresSessionState can be found in the System.Web.SessionState namespace.

like image 169
Michael Morton Avatar answered Sep 18 '22 16:09

Michael Morton