* Solution for the Session value inaccessible to the ashx File,
This example describes how to solve the problem that the *. ashx file cannot access the Session value. Share it with you for your reference. The specific method is as follows:
The instance code is as follows:
<% @ WebHandler Language = "C #" Class = "productHandler" %> using System; using System. web; using JBTCard. entity. companyEntity; using JBTCard. business. companyBS; using System. collections. generic; using Newtonsoft. json; using System. web. sessionState; public class productHandler: IHttpHandler, IRequiresSessionState, IReadOnlySessionState {public void ProcessRequest (HttpContext context) {string moduleId = Context. request. form ["moduleId"]. toString (); string message = ""; switch (moduleId) {case "getPTypeList": IList <ProductTypeIdNameEntity> list = ProductTypeBS. getPTypeListIdName (); message = JavaScriptConvert. serializeObject (list); break; case "getCompanyById": int cid = Convert. toInt32 (context. session ["cid"]); CompanyEntity company = CompanyBS. getCompanyEntyById (1); message = JavaScriptConvert. SerializeObject (company); break; case "insert": string condis = context. request. form ["condi"]. toString (); ProductEntity model = (ProductEntity) JavaScriptConvert. deserializeObject (condis, typeof (ProductEntity); bool B = ProductBS. addProduct (model); if (B) {message = "{success: true}" ;}else {throw new Exception ("failed to add product! ");} Break;} context. response. contentType = "text/javascript"; context. response. write (message) ;}public bool IsReusable {get {return false ;}}}
In fact, just add this sentence:
using System.Web.SessionState;
I hope this article will help you design your asp.net program.