Recently, I need to make an interface that responds to specific requests. It is only processed internally and there is no UI. In this case, of course, IHttpHandler is used to implement IHttpHandler, which can reduce the time of loading HTML controls. I originally thought so. Regarding the two methods defined in IHttpHandler, ProcessRequest(HttpContext ctx) and IsRunable(), I saw that there is an input parameter of HttpContext in ProcessRequest(HttpContext ctx). I thought that through this Can be used with all server objects, but requires a reference to HttpContext in front. But a problem arises. Session needs to be written in this custom HTTP response processing header. Other Requests and Responses can be referenced by using HttpContext, but Session just doesn’t work. There is always an error that the object is not referenced. It’s really a hundred It's puzzling. The HTTPCONTEXT lists the server objects that can be used, but SESSION cannot be used! It's really hard, so I have to put the content of the customized HTTPHANDLER into the ordinary WEBFORM. Just after finishing it, I accidentally discovered the method of using SESSION in the custom HTTPHANDLER!
1. First reference the System.Web.SessionState namespace.
2. If you want to read the contents of Session in HttpHandler, you must also implement the IReadOnlySessionState interface in the class that implements IHttpHandler.
3. If you want to read and write the contents of Session in HttpHandler, you must also implement IRequiresSessionState in the class that implements IHttpHandler,
so that Session can be used normally in the custom HttpHandler.