.ashx中引用 session必須 using System.Web.SessionState ,繼承IReadOnlySessionState/IRequiresSessionState
IReadOnlySessionState,為只讀的session 不可以修改
IRequiresSessionState ,可以修改。
using System;
using System.Web;
using System.Text;
using System.Web.SessionState; //這是在.ashx 中引用session 的必備條件之一
public class GetCheckData : IHttpHandler,IRequiresSessionState //繼承IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string ds="1234";
context.Session["ds"] = ds;//這只是簡單的使用方法,可以根據自己的要求改
HttpContext.Current.Session["ds"]=ds;//第二種方法
context.Response.Write(ds);
}
}