C#一般處理程序中使用Session


<%@ WebHandler Language="C#" Class="ChangePwd" %>

using System;
using System.Web;
using System.Web.SessionState;
public class ChangePwd : IHttpHandler, IReadOnlySessionState
{
   
    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;
        }
    }

}

加上 using System.Web.SessionState;和 IReadOnlySessionState

如果您的處理程序將訪問會話狀態值,它必須實現 IRequiresSessionState 接口(不包含任何方法的標記接口)。

導入using System.Web.SessionState;
果然,只要對自定義類加上一個IRequiresSessionState標記接口就可以了,也不需要實現任何的方法。
與此,同時還有另一個接口:IReadOnlySessionState接口,用於指示Http處理程序,對Session有只讀的權限,也是空接口,無需實現任何方法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM