session在一般处理程序中怎么传??

这范儿很好 |浏览875次
收藏|2019/03/18 14:53

满意回答

2019/03/18 15:18

在做AJAX的时候想在一般处理程序中设置Session,可以遇到麻烦了用 context.Session.Add()方法添加不进去,后来才发现这个得继承一个借口看下面: public class AuthticUser : IHttpHandler, IRequiresSessionState 加上红色部分的继承就ok啦

独家记忆__

其他回答(1)
  • 一般处理程序中使用session的方法如下:<%@WebHandlerLanguage="C#"Class="ChangePwd"%>usingSystem;usingSystem.Web;usingSystem.Web.SessionState;//出来session需要加上命名空间:usingSystem.Web.SessionState;和IReadOnlySessionStatepublicclassChangePwd:IHttpHandler,IReadOnlySessionState{//如果处理程序将访问会话状态值,它必须实现IRequiresSessionState接口(不包含任何方法的标记接口)。publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/plain";OperUserou=newOperUser();if(ou.ChangeWsPassword(context.Session["ws_user"].ToString(),context.Request.QueryString["pwd"].ToString())){context.Response.Write("true");}else{context.Response.Write("flase");}}publicboolIsReusable{get{returnfalse;}}}处理session同时还有另一个接口:IReadOnlySessionState接口,用于指示Http处理程序,对Session有只读的权限,也是空接口,无需实现任何方法。
    回答于 2019/03/18 15:32
0人关注该问题
+1

 加载中...