Aakash N

Aakash N

  • NA
  • 166
  • 19.7k

session variables-null/lost - IIS after 20-30 secs when idle

Jan 7 2019 2:33 PM
I am working on a project where we use SQL server session and set and get variables from the table. When working with Visual studio it works normal but, on IIS remote server the session variables are lost immediately if we keep application idle for 20-30 seconds.
 
Here is the startup.cs code:
  1. services.AddDataProtection().SetDefaultKeyLifetime(TimeSpan.FromDays(14));  
  2.             //.PersistKeysToFileSystem(new DirectoryInfo("./Keys/"));  
  3.             services.AddDistributedMemoryCache();  
  4.             services.AddHttpContextAccessor();  
  5.             services.ConfigureApplicationCookie(options => {  
  6.                 options.Cookie.Expiration = TimeSpan.FromMinutes(30);  
  7.                 options.ExpireTimeSpan = TimeSpan.FromDays(3);  
  8.             });  
  9.             services.AddSession(options =>  
  10.             {  
  11.                 options.Cookie.Name = ".app.Session";  
  12.                 options.IdleTimeout = TimeSpan.FromMinutes(30);  
  13.                 options.Cookie.HttpOnly = true;  
  14.                 options.Cookie.IsEssential = true;  
  15.                 options.Cookie.SecurePolicy = CookieSecurePolicy.None;  
  16.             });  
  17.             services.AddStactive();  
And web.config:
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <configuration>  
  3.   <system.webServer>  
  4.     <handlers>  
  5.       <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />  
  6.     </handlers>  
  7.     <aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">  
  8.       <environmentVariables />  
  9.     </aspNetCore>  
  10.     <directoryBrowse enabled="true" />  
  11.     <defaultDocument enabled="true" />  
  12.     <security>  
  13.       <requestFiltering allowDoubleEscaping="true" />  
  14.     </security>  
  15.   </system.webServer>  
  16. </configuration>  
Do I need to add any extra configuration either in startup.cs or web.config to make sure session values are available until the SQL session is Timeout?

My current project is developed using ASP.NET core 2.1

Can someone help me with this situation on handling session variables on IIS servers?

Thanks!!

Answers (4)