0

As stated in the title, this questions concerns a .NET 4.5 WebForms App. Despite using an InProc mode and a single instance only, my session timeout is not respected.

<sessionState timeout="240" mode="InProc" customProvider="DefaultSessionProvider">

In the above example, session is timed out after 20 minutes only. I am NOT using .NET forms authentication.

Thanks for your advice.

  • Sounds like the app pool or app domain is recycling. I did a quick search but only found blog posts from a couple years ago. Look into extending the app pool life or working around the recycle – mgiesa Nov 15 '15 at 05:42
  • @mgiesa you are right, this is about recycling which has to be disabled. I will give the solution to my question thanks –  Nov 16 '15 at 22:59

2 Answers2

1

If you want to maintain session state you have to use one of the following options

  • SQL Session State Provider using Azure SQL
  • Azure Table Session State
  • Session State with Azure Redis Cache

You can find details on how to do this at the following links:

The easiest way in my opinion is using Azure Redis Cache as noted in the link above.

Let me know if this helps!

Joe Raio
  • 1,795
  • 1
  • 12
  • 17
  • Hi Joe, thanks for your time. However, this is not about changing the session state provider to maintain state - inproc works perfectly with single instance deployments. It is only about the timeout parameter not being respected for some obscure reason .. –  Nov 12 '15 at 18:45
  • I see. I will do some more research and see what I can find. Tx for the clarification. – Joe Raio Nov 12 '15 at 19:08
0

To answer my own question, this is because of the automatic recycling of Azure cloud service web role, which has to be disabled. The role is recycled after 20 minutes (IIS default) before the session timeout expires.

Simon Pedersen describes the issue and gives a solution on the following page: http://wp.sjkp.dk/windows-azure-websites-and-cloud-services-slow-on-first-request/

He talks about the slow startup, but the reason my session timeout is not respected is the same. However, Pedersen's answer contains a small issue - the startup command file must be terminated with an exit code (else roles cannot start) as follows:

IF "%ComputeEmulatorRunning%" == "false" (
    REM *** Prevent the IIS app pools from shutting down due to being idle.
    REM %windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00
    REM *** Prevent IIS app pool recycles from recycling on the default schedule of 1740 minutes (29 hours).
    REM %windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.time:00:00:00
)
EXIT /B 0

PS As I want to change IIS parameters only in the cloud, I added a runtime environment variable (which is verified in startup command file, see above) to the servicedefinition.csdef as follows:

<Runtime>
  <Environment>
    <Variable name="ComputeEmulatorRunning">
      <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
    </Variable>
  </Environment>
</Runtime>