入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

C#,asp.net,ashx处理session

创建时间:2016-11-30 投稿人: 浏览次数:1162

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

}

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像