C# 在通用处理程序mvc中获取会话数据

C# 在通用处理程序mvc中获取会话数据,c#,asp.net-mvc,generic-handler,C#,Asp.net Mvc,Generic Handler,当我试图从通用处理程序中检索会话值时,它抛出“对象引用未设置为对象- public class Upload : IHttpHandler { public void ProcessRequest(HttpContext context) { Int32 UserId=Convert.ToInt32(context.Session["UserId"]); } } 如何解决这个问题 多谢各位 更新 这个链接解决了我的问题 尝试context.Curr

当我试图从通用处理程序中检索会话值时,它抛出“对象引用未设置为对象-

public class Upload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
          Int32 UserId=Convert.ToInt32(context.Session["UserId"]);
    }
}

如何解决这个问题

多谢各位

更新 这个链接解决了我的问题

尝试
context.Current.Session[“UserId”]
HttpContext.Current
将为您提供正在进行的请求。