本篇內(nèi)容介紹了“*.ashx文件不能訪問(wèn)Session值的問(wèn)題怎么解決”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)公司是一家做網(wǎng)站、成都網(wǎng)站制作,提供網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),網(wǎng)站制作,建網(wǎng)站,按需網(wǎng)站開(kāi)發(fā),網(wǎng)站開(kāi)發(fā)公司,自2013年創(chuàng)立以來(lái)是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價(jià)值為核心業(yè)務(wù),全程參與項(xiàng)目的網(wǎng)站策劃設(shè)計(jì)制作,前端開(kāi)發(fā),后臺(tái)程序制作以及后期項(xiàng)目運(yùn)營(yíng)并提出專業(yè)建議和思路。實(shí)例代碼如下:
<%@ 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": IListlist = 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("商品添加失?。?); } break; } context.Response.ContentType = "text/javascript"; context.Response.Write(message); } public bool IsReusable { get { return false; } } }
其實(shí)只要加上這句就好了:
using System.Web.SessionState;
“*.ashx文件不能訪問(wèn)Session值的問(wèn)題怎么解決”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!