1.在aspx和aspx.cs中,都是以 Session["type"]="aaa" 和 string aaa=Session["type"].ToString() 或使用
HttpContext.Current.Session[strSessionName] = strValue;進行讀寫。
而在一般處理程序ashx中,Session都要使用context.Session,讀寫方法不變。
2.在ashx文件中,若要對Session進行成功的讀寫,要添加命名空間和接口,否則context.Session["type"]讀出的總是null。
命名空間:using System.Web.SessionState
增加接口:IRequiresSessionState
代碼如下:
public class pagingQuery : IHttpHandler, IRequiresSessionState
string type =context.Session["type"].ToString();