asp.net中ashx文件如何调用session

如果你要保证数据的安全性,你可以在ashx中使用session验证。
如:你的index.aspx中使用jquery回调ashx数据,那么在index.aspx page_loadsession["checked"]="true",在ashx中验证session是否存在。

ashx中要获取session内容还需如下几步:
①导入命名空间

using
System;
using
System.Web;
using
System.Web.SessionState;//第一步:导入此命名空间

②实现接口

publicclassMyWeb:IHttpHandler将此改为如下:

publicclassMyWeb:IHttpHandler,IRequiresSessionState//第二步:实现接口 到此就可以像平时一样用Session了

③调用方法

HttpContext.Current.Session["Session变量名称"]
原文地址:https://www.cnblogs.com/love828/p/3378917.html