为什么即使页面的 EnableSessionState=“False”,ASP.NET 也会访问状态服务器,但仅限于 VB.NET 站点,而不是 C# 站点?
我们的网站使用我们自己定制的会话状态管理,与 ASP.NET 会话状态分开。但由于少数特殊页面使用 SQL Server Reporting Services,我们还需要启用 ASP.NET 会话状态。由于我们处于负载平衡环境中,因此我们启用了 ASP.NET 状态服务器< /a> (aspnet_state.exe 或“进程外模式”)位于单独的后端计算机上。
今天我注意到,当我们暂时关闭在开发环境中运行状态服务的计算机时,开发网站停止工作(“无法向会话状态服务器发出会话状态请求。”)尽管 EnableSessionState="False"在正在加载的页面上。
为什么 ASP.NET 在为不使用会话状态的页面提供请求时需要连接到状态服务?即使页面不使用母版页、基本页或任何用户控件,这种情况似乎也会发生。我搜索了所有隐藏代码,以确保我们永远不会以编程方式重新启用会话状态或尝试访问它。
--- 更多故障排除后进行编辑 ---
正如下面的用户所建议的,我尝试从头开始创建一个网站来重新测试它,而不会因 httpHandlers、httpModules 或其他自定义逻辑而出现任何复杂情况。
- 我使用 Visual Studio 2008使用 VB.NET 创建了一个新的“ASP.NET 网站”。
- 我通过 VS 运行该站点,允许它启用调试模式并生成标准的 web.config 文件。
- 我在
元素下添加了
并启动了本地 ASP .NET State Service”。 - 我将 Default.aspx 页面的 EnableSessionState 更改为 False 并重新加载页面 = OK。
- 我停止了 ASP.NET State Service 并重新加载页面 =“无法使向会话状态服务器发送会话状态请求。”
此时我很困惑,因为其他用户声称他们尝试过类似的操作,但没有遇到相同的问题。所以我想知道这是否与使用 VB.NET 有关(愚蠢)虽然听起来不错。)越来越多的人使用 C# 来实现 ASP.NET,所以我用 C# 网站重新进行了上面的测试,你瞧,访问页面时没有例外!我只得到了一个例外如果我将 EnableSessionState 设置为 True 并且实际上在代码中访问了 Session 集合
这证明 ASP.NET 中的 VB.NET 站点的行为略有不同,因为它们访问每个页面上的会话状态,即使页面不需要这样做。不幸的是,这并没有回答我最初的问题:为什么?
我将把这个交叉发布到官方 ASP.NET 论坛,看看那里是否有专家可以提供一些启发。
Our website uses our own custom-built session state management separate from ASP.NET Session State. But because a handful of special pages use SQL Server Reporting Services, we also need to enable ASP.NET Session State. Since we are in a load-balanced environment, we enabled the ASP.NET State Server (aspnet_state.exe or "Out-of-process Mode") on a separate backend machine.
Today I noticed that when we temporarily brought down the machine running the State Service in our Dev environment, the Dev website stopped working ("Unable to make the session state request to the session state server.") This despite having EnableSessionState="False" on the page being loaded.
Why would ASP.NET need to connect to the State Service when serving a request for a page that does not use Session State? This seems to happen even if the page does not use a Master Page, Base Page, or any User Controls. I searched through all our code-behind to ensure that we never programmatically re-enable Session State or attempt to access it.
--- EDIT AFTER MORE TROUBLESHOOTING ---
As suggested by a user below, I tried creating a web site from scratch to retest this without any complications from httpHandlers, httpModules, or other custom logic.
- I used Visual Studio 2008 to create a new "ASP.NET Web Site" using VB.NET.
- I ran the site through VS, allowing it to enable debug mode and generate a standard web.config file.
- I added
<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" />
under the<system.web>
element and started my local ASP.NET State Service". - I changed the Default.aspx page's EnableSessionState to False and reloaded the page = OK.
- I stopped the ASP.NET State Service and reloaded the page = "Unable to make the session state request to the session state server."
At this point I was puzzled because other users claimed that they had tried something similar and did not experience the same issue. So I wondered if it had anything to do with using VB.NET (silly though that sounds.) More people use C# for ASP.NET, so I redid my test above with a C# web site, and lo and behold, no exception when accessing the page! I only got an exception if I set EnableSessionState to True and actually accessed the Session collection in code.
This proves that VB.NET sites in ASP.NET behave slightly differently in that they access session state on each page, even if the page does not need to. Unfortunately this doesn't answer my original question: Why?
I am going to cross-post this to the official ASP.NET forums and see if any gurus there can shed some light.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的 Web 应用程序中查找任何 HttpHandler 或 HttpModule。这些完全有可能需要会话状态,即使您的页面不需要。
Look for any HttpHandlers or HttpModules in your web application. It's entirely possible that these are requiring session state even though your pages are not.
你缺少一些东西。因为在 ASP.NET Web 窗体中默认页面处理程序( Page 类)默认情况下不实现“IRequiresSessionState”接口。我已经在批量 ASP.NET 网站上尝试过您的案例:
您可以轻松地重复相同的实验。
You are missing something. Because in ASP.NET Web Forms default page handler ( Page class ) doesn't implement "IRequiresSessionState" interface by default. I've tried your case with bulk ASP.NET website:
you can repeat same experiment easily.
抱歉,这可能看起来很明显,但是您检查过 Global.asax 吗?
Sorry this may seem obvious but have you checked Global.asax?
每个页面请求都会命中底层的会话提供者来标记存储会话访问时间,这样会话就不会被意外清理。无论 EnableSessionState 的值如何,也无论会话状态模式(InProc、StateServer,...)如何,先前的状态都是 true。
Every page request hits the underlying session provider to mark the store the session accessed time so that the session will not be cleaned up by accident. The previous state is true irrespective of the value of EnableSessionState and irrespective of Session State mode (InProc, StateServer,....).