C#使用一般處理程序(ashx)中session


.ashx中引用 session必須 using System.Web.SessionState ,繼承IReadOnlySessionState/IRequiresSessionState

IReadOnlySessionState,為只讀的session 不可以修改

IRequiresSessionState ,可以修改。

using System;
using System.Web;
using System.Text;
using System.Web.SessionState; //這是在.ashx 中引用session 的必備條件之一

 public class GetCheckData : IHttpHandler,IRequiresSessionState //繼承IRequiresSessionState
 {

   public void ProcessRequest(HttpContext context)
    {        
       context.Response.ContentType = "text/plain";

       string ds="1234";

       context.Session["ds"] = ds;//這只是簡單的使用方法,可以根據自己的要求改

       HttpContext.Current.Session["ds"]=ds;//第二種方法

       context.Response.Write(ds);

    }   

}


免責聲明!

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



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