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