Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ASP.NET access the State Server even when the page's EnableSessionState="False", but only for a VB.NET site, not a C# site?

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.

  1. I used Visual Studio 2008 to create a new "ASP.NET Web Site" using VB.NET.
  2. I ran the site through VS, allowing it to enable debug mode and generate a standard web.config file.
  3. I added <sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" /> under the <system.web> element and started my local ASP.NET State Service".
  4. I changed the Default.aspx page's EnableSessionState to False and reloaded the page = OK.
  5. 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.

like image 497
Jordan Rieger Avatar asked Oct 05 '11 21:10

Jordan Rieger


2 Answers

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.

like image 133
Chris Disley Avatar answered Nov 15 '22 10:11

Chris Disley


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:

  1. Session was enabled in web.config (StateServer mode), whilst page's EnableSessionState was disabled - requests to default.aspx were processed successfully with StateServer being shut down.
  2. After enabling page's EnableSessionState - it began throwing exceptions like yours.

you can repeat same experiment easily.

like image 25
Timur Sadykov Avatar answered Nov 15 '22 10:11

Timur Sadykov