session在一般处理程序中怎么传??
session在一般处理程序中怎么传值出去?用的是邮箱验证,求大神!
在做ajax的时候想在一般处理程序中设置Session,可以遇到麻烦了用 context.Session.Add()方法添加不进去,后来才发现这个得继承一个借口看下面: public class AuthticUser : IHttpHandler, IRequiresSessionState 加上红色部分的继承就ok啦
一般处理程序中使用session的方法如下:
<%@ WebHandler Language="C#" Class="ChangePwd" %> using System; using System.Web; using System.Web.SessionState; //出来session需要加上命名空间:using System.Web.SessionState;和 IReadOnlySessionStatepublic class ChangePwd : IHttpHandler, IReadOnlySessionState { //如果处理程序将访问会话状态值,它必须实现 IRequiresSessionState 接口(不包含任何方法的标记接口)。 public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; OperUser ou = new OperUser(); if (ou.ChangeWsPassword(context.Session["ws_user"].ToString(),context.Request.QueryString["pwd"].ToString())) { context.Response.Write("true"); } else { context.Response.Write("flase"); } } public bool IsReusable { get { return false; } } }
处理session同时还有另一个接口:IReadOnlySessionState接口,用于指示Http处理程序,对Session有只读的权限,也是空接口,无需实现任何方法。
热门标签: