我正在使用ASHX处理程序,我希望处理程序检查Session!= null.
I'm using an ASHX handler, i want the handler to check if Session != null.
if (context.Session["Username"] != null)我在指向此行时遇到此错误:
And i get this error pointing this line:
System.NullReferenceException:对象引用未设置为对象的实例.
System.NullReferenceException: Object reference not set to an instance of an object.
出什么问题了?
推荐答案if (context.Session["Username"] != null)
您的处理程序是否实现 IRequiresSessionState ?否则,会话可能不可用.
Does your handler implement IRequiresSessionState? Otherwise Session might not be available.
来自 MSDN :
指定目标HTTP处理程序 需要对以下内容的读写权限 会话状态值.这是一个标记 界面,没有任何方法.
Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.
更多推荐
System.NullReferenceException当检查!= null时
发布评论