【发布时间】:2012-03-11 00:54:05
【问题描述】:
我有以下简单的处理程序(为了可见性而删除了一些代码,但下面仍然失败)
<%@ WebHandler Language="C#" Class="DownloadHandler" %>
using System;
using System.Web;
public class DownloadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Session["t1"] != "true")
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
if (context.Session["t1"] != "true") 行因“未将对象引用设置为对象的实例”而失败。我不太明白这是为什么?
【问题讨论】:
-
null是什么对象?是context还是context.Session? -
抱歉 - 找到了我自己问题的答案。应添加
IRequiresSessionState(如public class DownloadHandler : IHttpHandler, IRequiresSessionState)
标签: c# asp.net session handler