C#,asp.net,ashx处理session

来源:互联网 发布:淘宝怎样修改评价 编辑:程序博客网 时间:2024/06/08 03:58

要想在.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);

    }

   public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

0 0
原创粉丝点击