我有一个 ASHX 文件:
对象引用未设置为
对象的实例。
在线上:
HttpContext.Current.Session["loggedIn"] = true
这是我正确使用会话的方式吗?
我猜想Session
是这里的罪魁祸首;供参考here https://stackoverflow.com/questions/1382791/asp-net-what-to-do-if-current-session-is-null,您可能想尝试添加: IRequiresSessionState
到您的处理程序(ashx 的代码隐藏)。所以你应该有类似的东西:
public class Handler1 : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
context.Session["loggedIn"] = true;
}
public bool IsReusable
{
get
{
return false;
}
}
}
另请注意,与context
通过了,但是HttpContext.Current
也应该有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)