Why does ASP.NET get access to the state server, even if the page EnableSessionState = "False", but only for the VB.NET site, and not for the C # site?

Our website uses our own custom session management separate from the ASP.NET session state. But since several special pages use SQL Server Reporting Services, we also need to enable ASP.NET session state. Because we are in a load-balanced environment, we enabled ASP.NET State Server (aspnet_state.exe or "Out-of-Mode Mode") on a separate server machine.

Today, I noticed that when we temporarily crashed a car with public service in our Dev environment, the Dev site stopped working ("Failed to make a request for session state to the session state server"). This is despite having EnableSessionState = "False" on the loaded page.

Why should ASP.NET connect to the public service when serving a request to a page that does not use session state? This happens even if the page does not use the main page, the base page, or any user controls. I reviewed all of our code to ensure that we will never programmatically re-enable session state or attempt to access it.

--- CHANGE AFTER MORE TROUBLESHOOTING ---

As suggested below, I tried to create a website from scratch to test it without any complications from httpHandlers, httpModules or other user logic.

  • I used Visual Studio 2008 to create a new โ€œASP.NET websiteโ€ using VB.NET .
  • I launched the site through VS, allowing it to enable debug mode and create 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 public service ".
  • I changed the Default.aspx EnableSessionState page to False and reloaded the page = OK.
  • I stopped the ASP.NET State Service and reloaded the page = "Failed to complete the session state request to the session state server."

At this point, I was puzzled because other users claimed that they tried something similar and did not experience the same problem. So I wondered if this was related to using VB.NET (this is stupid, although it sounds.) More people use C # for ASP.NET, so I redid my test above with the C # website, and now, without page access exceptions! I only got an exception if I set EnableSessionState to True and actually got access to the session collection in code.

This proves that VB.NET sites in ASP.NET behave somewhat differently, as they access the session state on each page, even if the page is not needed. Unfortunately, this does not answer my original question: Why?

I'm going to cross-post this on the official ASP.NET forums and see if any gurus can shed some light.

+7
source share
4 answers

Find any HttpHandlers or HttpModules in your web application. It is possible that this requires a session state, even if your pages are not.

+2
source

Something is missing for you. Because in ASP.NET Web Forms, the default page handler (Page class) does not implement the default IRequiresSessionState interface. I tried your case with a massive ASP.NET site:

  • The session was enabled in web.config mode (StateServer mode), while the EnableSessionState page was disabled - requests to default.aspx were successfully processed when StateServer was turned off.
  • After enabling the EnableSessionState page, it started throwing exceptions like yours.

you can easily repeat the same experiment.

+1
source

Sorry, this may seem obvious, but have you checked Global.asax?

0
source

Each page request goes to the base session provider to mark storage, session access time so that the session is not cleared accidentally. The previous state is true regardless of the value of EnableSessionState and regardless of the session state mode (InProc, StateServer, ....).

0
source

All Articles