asp.net在自定义httpHandler中使用会话

asp.net在自定义httpHandler中使用会话,asp.net,Asp.net,我在app_code文件夹中有一个自定义的httphandler,我想在这个类中使用session,但是有一条异常消息,下面是代码 public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; HttpContext.Current.Session["UserID"] =

我在app_code文件夹中有一个自定义的httphandler,我想在这个类中使用session,但是有一条异常消息,下面是代码

public void ProcessRequest(HttpContext context)
{
    HttpRequest request = context.Request;
    HttpResponse response = context.Response;

    HttpContext.Current.Session["UserID"] = "ABC";
    response.Write(HttpContext.Current.Session["UserID"].ToString());

}
错误消息:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

任何人都知道问题出在哪里>

如果您想在HttpHandler中创建可删除的会话状态,您应该从marker接口继承处理程序


若您想在HttpHandler中创建可扩展的会话状态,您应该从marker接口继承处理程序


您需要使处理程序实现
IReadOnlySessionState
irerequiresessionstate
(用于写访问)。

您需要使处理程序实现
IReadOnlySessionState
irerequiresessionstate
(用于写访问).

您需要实现才能从HttpHandler访问会话

这是一个很好的例子

请注意,没有要实现的方法,只需让您的处理程序实现接口。

您需要实现才能从HttpHandler访问会话

这是一个很好的例子


请注意,没有要实现的方法,只需让处理程序实现接口。

错误发生在哪里?错误发生在哪里?添加后:编译器错误消息:CS0246:找不到类型或命名空间名称“IRequiresessionState”(是否缺少using指令或程序集引用?),使用System.Web.SessionState;时缺少Station?@hkSession?添加后:编译器错误消息:CS0246:找不到类型或命名空间名称“IRequiresessionState”(是否缺少using指令或程序集引用?),缺少using STATTE?@HKSESSION using System.Web.SessionState?
   using System.Web.SessionState;

    public class handler: IHttpHandler, IRequiresSessionState
    {

    }