开发者

Check if session is null is returning error

开发者 https://www.devze.com 2023-01-19 06:42 出处:网络
I\'m using jQuery to get a few values and them i send to an 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 se

I'm using jQuery to get a few values and them i send to an 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.NullRef开发者_StackOverflow社区erenceException' occurred in PromotorDeSaude.DLL".

I'm checking if session is null like this:

if (HttpContext.Current.Session["encomenda"] != null)

Am i doing something wrong?


To access Session in a web service method, add the attribute

[WebMethod(EnableSession = true)]

to the method. See http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx for more information.


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.

I suggest you log every bit of the expression to find out which bit is null, and work from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消