user5033226
user5033226

Reputation:

Microsoft Azure .NET 4.5 WebForms App : Session TimeOut / InProc / Single Instance

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.

Upvotes: 0

Views: 1172

Answers (2)

user5033226
user5033226

Reputation:

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>    

Upvotes: 0

Joe Raio
Joe Raio

Reputation: 1805

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!

Upvotes: 1

Related Questions