locked
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? RRS feed

  • Question

  • User921092864 posted

    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.

    As suggested by another user, 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?

    P.S. This is cross-posted from http://stackoverflow.com/questions/7668020/why-does-asp-net-access-the-state-server-even-when-the-pages-enablesessionstate but even after an open bounty, I haven't got a satisfying answer yet.

    Any gurus here able to shed some light?

    Monday, October 17, 2011 2:12 PM

All replies

  • User-1856974186 posted

    I can't see any reason why the language would make any difference. I can't repro it in a new site either; I created a new ASP.NET Web Site in VS 2008, added the session state config (as above), set EnableSessionState on the page to false and ran it; it worked fine, both with and without the state service running.

    Have you checked the base configuration in C:\Windows\Microsoft.NET\Framework\v...\config? Check machine.config and make sure there are no additional modules and handlers in there.

    Can you zip up the test sites and upload them? Perhaps to skydrive.live.com? Let me know and I'll see if I can repro with your projects.

    Tuesday, October 18, 2011 6:01 AM
  • User-1598917946 posted

    This is very interesting

    In your VB and C# site in the web config <sessionState mode="StateServer" cookieless="UseUri" stateConnectionString="tcpip=localhost:42424" />

    and set EnableSesssionState="false" on the page and see what you are recieving in the URI's of both pages and post your answer here

    Tuesday, October 18, 2011 6:18 AM
  • User921092864 posted

    Hi Dave,

    I agree, the language should make no difference. I have uploaded repro web sites to https://skydrive.live.com/embedicon.aspx/.Public?cid=9e88c63d0d5f07e4&sc=documents for you to review if you want. The "WebSites.zip" file contains another zip file with the contents of my C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG folder (didn't seem like anything interesting though.)

    I also tried to reproduce this on my home PC running VS 2010 Express but it works fine there, no exception is thrown if EnableSessionState is False, the same in C# as in VB.NET. Unforunately I don't have access to a full version of VS 2008 on another PC that I can play with.

    Thursday, October 20, 2011 7:22 PM
  • User921092864 posted

    In your VB and C# site in the web config <sessionState mode="StateServer" cookieless="UseUri" stateConnectionString="tcpip=localhost:42424" />

    and set EnableSesssionState="false" on the page and see what you are recieving in the URI's of both pages and post your answer here

    When I try that, the exception no longer occurs. However, the URL in the browser address bar does not change (no redirection is performed.)

    Thursday, October 20, 2011 7:26 PM
  • User-1598917946 posted

    I am not sure .. But it seems as if no session is generated but in VB the compiler is looking for an empty session rather then a null session

    Friday, October 21, 2011 12:33 AM
  • User-1856974186 posted

    Jordan

    Sorry for the delay; been out for a few days.

    I've tried your samples and get the expected result; no errors. I'm a bit stumped now

    Tuesday, October 25, 2011 4:04 AM
  • User921092864 posted

    I've tried your samples and get the expected result; no errors. I'm a bit stumped now

    OK, in that case it must be machine/environment-specific. Also the fact that it doesn't repro in VS 2010 is comforting. It was mostly just a curiosity. I doubt the state service will ever go down in our Live environment, aside from a complete server outage.

    Thanks for your help.

    Tuesday, October 25, 2011 4:26 AM