ashx页面怎么调用Handler的Session

aspx里面直接可以用Session["Name"]进行赋值和取值,ashx中就得继承接口IRequiresSessionState。然后使用!

实现:

public class UserInfo : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        var userinfo = context.Session["userinfo"];
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

  

下面的代码示例检查当前的 HTTP Handler 属性来确定是否需要读取和写入访问为会话状态的值。

bool requiresSession = false;if (Context.Handler is IRequiresSessionState)
  requiresSession = true;
 

文章引用:http://code365.club/Article?id=19

猜你喜欢

转载自www.cnblogs.com/code365/p/8855988.html