Read this post first:
How can I capture a session in httpmodule?
Http://topic.csdn.net/u/20070226/10/9db317e8-0400-4d92-9c93-83a90d6bcde5.html
The following is an explanation on msdn:
Overview of ASP. NET application lifecycle in IIS 5.0 and 6.0
Http://msdn.microsoft.com/zh-cn/library/ms178473 (V = vs.80). aspx
When processing this requestHttpapplicationClass to execute the following events. Want to expandHttpapplicationClass developers need to pay special attention to these events.
When a request is verified, the browser checks the information sent and determines whether it contains a potentially malicious flag. For more information, see validaterequest and script intrusion overview.
If you have configured any URL in the urlmappingssection of the web. config file, perform URL ing.
The beginrequest event is triggered.
The authenticaterequest event is triggered.
This triggers the postauthenticaterequest event.
The authorizerequest event is triggered.
This triggers the postauthorizerequest event.
This triggers a resolverequestcache event.
The postresolverequestcache event is triggered.
Based on the file extension of the requested resource (ing in the application configuration file), select an ihttphandler class to process the request. If the request is for an object (PAGE) derived from the page class and needs to compile the page, ASP. NET will compile the page before creating an instance.
The postmaprequesthandler event is triggered.
The acquirerequeststate event is triggered.
This triggers the postacquirerequeststate event.
Raises the prerequesthandlerexecute event.
Call the appropriateIhttphandlerClass processrequest method (or asynchronous beginprocessrequest ). For example, if the request is for a page, the current page instance processes the request.
The postrequesthandlerexecute event is triggered.
This triggers the releaserequeststate event.
The postreleaserequeststate event is triggered.
If the filter attribute is defined, the response is filtered.
The updaterequestcache event is triggered.
This triggers the postupdaterequestcache event.
An endrequest event is triggered.
Select ihttphandler in step 1, generate httpsessionstate in step 2, and callIhttphandlerClass processrequest method. In other wordsIhttphandlerWhen the processrequest method of the class is called, httpsessionstate has been prepared for a long time. But why is it true that the result is null? The reason is that we didn't implement this for ourselves.IhttphandlerClass is displayed with "we want to use session "!
Solution:
Let the class that implements the ihttphandler interface you write implement another irequiressessionstate interface. This interface does not have anything, however, it will make your class implementing ihttphandler get a non-null httpsessionstate!
Let's take a look at the description of the irequiressessionstate interface:
Http://msdn.microsoft.com/zh-cn/library/system.web.sessionstate.irequiressessionstate.aspx
Specify the target HTTP handler to have read and write access to the session status value. This is a tag interface and there is no way.