一般处理程序中如何设置Session

ASP.NET中在一般处理程序中使用session的方法如下:

<%@ WebHandler Language="C#" Class="ChangePwd" %> 
using System; 
using System.Web; 
using System.Web.SessionState; 
//出来session需要加上命名空间:using System.Web.SessionState;和 IReadOnlySessionState
public 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有只读的权限,也是空接口,无需实现任何方法。

 

(http://zhidao.baidu.com/link?url=DRYG2YePVkGqgMR5nAeSdbotRvpLdCg9rjIdii1f8qzHEFcfZwDIrGsMxwuvPe9_vMzHwWFT5N_crV7yEs9TQLDwRZLCuGcDzqSYU3fnUNy)

posted on 2016-02-04 10:38  springgao_2007  阅读(405)  评论(0编辑  收藏  举报

导航