System.Web.HttpContext.Current.Session为NULL解决方法

http://www.cnblogs.com/tianguook/archive/2010/09/27/1836988.html

自定义 HTTP 处理程序,从IHttpHandler继承,在写System.Web.HttpContext.Current.Session["Value"]的时 候,没有问题,但想将这个Session写到某个变量时或判断是否为空时 如:HttpContext.Current.Session["Value"]==null,发现Session的值为NULL,后来查MSDN,看到 “在自定义 HTTP 处理程序中实现 IRequiresSessionState 接口,以确定处理程序是否需要对会话状态值具有读写访问权”,在自定义那个类上加上该接口后,果然正常了。

  在使用asp.net编写webservice时,默认情况下是不支持session的,但我们可以把WebMethod的EnableSession选项设为true来显式的打开它,如下:  

[WebMethod(EnableSession = true)]

public string Login(string name)

{

    Context.Session["name"] = name;

    return name;

}

原文地址:https://www.cnblogs.com/feigao/p/5786283.html