On the general transaction processing page, you can easily obtain the request and response objects and perform the following operations:
Httprequest request = context. request;
Httpresponse response = context. response;
However, it is not that easy to obtain the session value. For example, you need to obtain the Logon account session ["useraccount"] stored in the session in ashx.
If you only use context. session ["useraccount"], an exception will be reported "the object has not been referenced to the instance of the object ".
Therefore, if you want to obtain the value in the session, you need
1. Introduce the namespace:
Using system. Web. sessionstate;
2. Implement the irequiressessionstate interface as follows:
/// Summary description of <summary> /// $ codebehindclassname $ /// </Summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] public class adduserinfo: ihttphandler, irequiressessionstate // This is the implementation of the display, there is no need to implement any method {public void processrequest (httpcontext context ){//... // you can perform the following operations: If (context. session ["useraccount"]! = NULL) {string account = context. session ["useraccount"]. tostring () ;}//... continue the following code }}
How to get the session value on the ashx page