“System.Web.HttpContext.Current.Session”为空

发布于 2024-11-19 14:37:40 字数 643 浏览 1 评论 0原文

我有一个 ASP.NET 网站,自 2008 年开始部署,拥有大量用户。我不时地对网站进行更新并将这些更改上传到服务器,没有出现任何问题。

然而,今天,我尝试在我的开发环境中运行该网站,并且每当代码尝试访问会话状态时我都会收到错误。看来 System.Web.HttpContext.Current.Session 始终为 null!

关于去哪里看有什么建议吗?我已经有一段时间没有进行此工作了,并且不能 100% 确定我是否使用当前版本的 ASP.NET (4.0) 进行了此工作。

除此之外,代码一直运行良好,自上次运行以来我没有进行任何更改。

更多信息

我花了整个上午的时间来解决这个问题,但显然我有一个更大的问题。

如果我单步执行代码,我会看到我的页面加载处理程序执行。此时Session不为null。之后,我的专用母版页就会执行。之后,我的通用母版页就会执行。然后,我单步执行几个控件的加载事件。这一切看起来都很正常。

然后,如果我继续执行,突然我正在加载另一个页面的专用母版页,并且会话现在为空!

如果我按 F5,则会显示原始页面。但不知何故,它导致其他页面加载但没有会话状态。如果我关闭调试模式,它似乎可以正常运行。

显然,我发生了一些奇怪的事情。我需要确定为什么加载其他页面。

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 session 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

墨落成白 2024-11-26 14:37:40

尝试放置一个静态页面,例如 Test.aspx 并浏览到该页面。如果它被加载,请尝试在代码隐藏中使用页面的 Session 属性。您仍然收到错误吗?在这种情况下,会话不会加载。我建议创建一个 HTTP 模块并连接到一个负责加载会话信息的方法。看看出了什么问题。

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.

肤浅与狂妄 2024-11-26 14:37:40

只是猜测 - 您是否因任何原因停用了 sessionState?像这样的任何事情:

 <sessionState mode="Off"/>

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

 <sessionState mode="Off"/>
旧梦荧光笔 2024-11-26 14:37:40

我很抱歉。我提供的信息完全被误导,不足以解决问题。

该问题实际上是由于某些重定向到错误页面的自定义错误处理造成的。这是在 web.config 中配置的。这个错误页面正在使用我的代码神秘执行的母版页。

显然,GridView 控件内发生了错误。这是 ASP.NET 代码,而不是我自己的代码,因此我无法单步执行它或使用常规处理程序捕获它。

这很难理解。如果我正在执行错误页面的 Load 事件处理程序,那么这将是显而易见的。但它似乎跳过了这一点。于是,我的困惑。

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.

谎言 2024-11-26 14:37:40

尝试检查 global.asax 文件或任何其他预加载事件,并确保 Session 未显式设置为 NULL。

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

花开浅夏 2024-11-26 14:37:40

也许您出错的母版页正在从会话对象不可用的某些外部类调用代码?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文