Store ASP.NET Sessions in MS SQL Server

Store Sessions in MS SQL Server

Website users are being automatically logged out after being inactive for a period of time. The DotNetNuke event log may show this issue:
Shutdown Details: The AppDomain shut down because of the hosting environment.

This is a by-design feature of your website.  This occurs when your ASP.NET application pool recycles. The "AppDomain shut down because of the hosting environment" message does not mean that your site is offline, it simply means the site has not been accessed in a while and ASP.NET is uncaching it to preserve resources. 

To fix this problem, your website must be configured to use the SQL Server as the session state. Please follow these directions to do that. If you do not have a dedicated server this fix must be implemented by a support technician.
  1. Connect to the server using Remote Desktop.
  2. Click Start > Run and type cmd into the run dialogue box.
  3. Copy and paste the following command into your command prompt replacing [databasename] with the name of your sites database:
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql -ssadd -sstype c -d [databasename] -E
  4. Open the web.config of the site.
  5. Right before the </system.web>,  update the SESSIONSTATE node as follows:
    <sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="SQLCONNECTIONSTRING" />
The ASP.NET session state will now be stored in your website's database and will not be lost after the application pool recycles.

Add Feedback