ASP.Net一般处理程序Session用法

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();

 

posted @ 2018-11-29 10:37  咖啡无眠  阅读(997)  评论(0编辑  收藏  举报