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

人走茶凉 提交于 2019-12-12 04:43:35

问题


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.


回答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:

  • Session State Management in Windows Azure Web Roles
  • Session state with Azure Redis cache in Azure App Service

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

Let me know if this helps!




回答2:


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>    


来源:https://stackoverflow.com/questions/33659436/microsoft-azure-net-4-5-webforms-app-session-timeout-inproc-single-instan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!