开发者

'System.Web.HttpContext.Current.Session' is null

开发者 https://www.devze.com 2023-03-19 01:06 出处:网络
I have an ASP.NET website that has been deployed since 2008 with plenty of users. From time to time, I\'ve made updates to the site and uploaded those changes to the server without problems.

I have an ASP.NET website that has been deployed since 2008 with plenty of users. From time to time, I've made updates to the site and uploaded those changes to the server without problems.

However, today, I'm trying to run the site on my development environment and I keep getting errors any time the code tries to access ses开发者_JAVA百科sion state. It appears System.Web.HttpContext.Current.Session is always null!

Any suggestions on where to look? It's been a while since I worked on it and am not 100% sure if I've worked on it with the current version of ASP.NET (4.0).

Other than that, the code's been working fine and I haven't made any changes since it was last working.

More Information

I've spent all morning on this but I apparently have a larger issue.

If I step through the code, I see that my page Load handler executes. At this point, Session is not null. After that, my specialized master page executes. After that, my general master page executes. I then step through load events for a couple of controls. This all seems very normal.

Then, if I keep executing, suddenly I'm loading a specialized master page for another page and Session is now null!

If I hit F5, it the original page shows. But somehow it is causing the other page to load and without session state. If I turn off debug mode, it appears to run normally.

Obviously, I have something strange happening. I need to determine why the other page is being loaded.


Try to put a static page, something like Test.aspx and browse to that page. If it gets loaded, try to use Session property of the page in code behind. Do you still get the error? In that case, Session doesn't load. I suggest creating an HTTP Module and hooking into a method which is responsible for loading Session info. See what's wrong.


Just a guess - did you deactivate sessionState for any reason? Anything like this:

 <sessionState mode="Off"/>


My apologies. The information I provided was completely misguided and was not sufficient to resolve the issue.

The problem was actually due to some custom error handling that redirected to an error page. This was configured in web.config. This error page was using the master page that my code was mysteriously executing.

Apparently, an error was occurring within the GridView control. This is ASP.NET code and not my own, so I was unable to step through it or catch it with a regular handler.

This was hard to understand. If I was executing the Load event handler of my error page, then it would've been obvious. But it appears to have skipped over that. Thus, my confusion.


Try checking the global.asax file or any other pre-load events and make sure the Session is not set to NULL explicitly.


Maybe your erring master page is calling code from some external class where the session object is not available?

0

精彩评论

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