[英]Check if session is null is returning error
I'm using jQuery to get a few values and them i send to an Webservice. 我正在使用jQuery来获取一些值,并将它们发送到Webservice。 On that WebService i'm checking if a session is null but i'm receiving Null Reference to that session and it gets error (i see it on javascript console, on debugging i just see the error on output "A first chance exception of type 'System.NullReferenceException' occurred in PromotorDeSaude.DLL". 在该WebService上,我正在检查会话是否为null,但我收到对该会话的Null引用,并且会收到错误消息(我在javascript控制台上看到了它,在调试时,我只在输出中看到错误,即“类型为“第一次机会异常” PromotorDeSaude.DLL中发生“ System.NullReferenceException”。
I'm checking if session is null like this: 我正在检查会话是否为空,像这样:
if (HttpContext.Current.Session["encomenda"] != null)
Am i doing something wrong? 难道我做错了什么?
That suggests that HttpContext.Current
or HttpContext.Current.Session
may be null - which would happen if you're running on a different thread, for example. 这表明HttpContext.Current
或HttpContext.Current.Session
可能为HttpContext.Current.Session
例如,如果您在其他线程上运行,则会发生这种情况。
I suggest you log every bit of the expression to find out which bit is null, and work from there. 我建议您记录表达式的每一位,以找出哪一位为空,然后从那里开始。
To access Session in a web service method, add the attribute 要以Web服务方法访问Session,请添加属性
[WebMethod(EnableSession = true)]
to the method. 方法。 See http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx for more information. 有关更多信息,请参见http://msdn.microsoft.com/zh-cn/library/system.web.services.webmethodattribute.enablesession.aspx 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.