I am not able to increase the session timeout more than 20 minutes in ASP.NET Core 6.0. Session gets expired after every 20 minutes not in debug mode but in IIS (Hosted after publish),For load balancing the application is hosted on 2 server and use AddDistributedMemoryCache property. Session changes are done in Application side as well as IIS side also. Below are the changes done for increase session time to 40 minutes in ASP.NET Core 6.0.
# **1.Application Changes** ------------------------------ Program.cs ---------------------------------------- builder.Services.AddDistributedMemoryCache(); string sessionTimeout = Convert.ToString(config.GetSection("AppSettings").GetSection("SessionTimeout").Value); int sessiontime = int.Parse(sessionTimeout); builder.Services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(sessiontime); options.Cookie.SecurePolicy = CookieSecurePolicy.Always; options.Cookie.SameSite = SameSiteMode.Strict; }).AddDistributedMemoryCache(); if (config.GetSection("AppSettings").GetSection("Envoirnment").Value != "Development") { app.UseCors(); app.UseHsts(); app.UseHttpsRedirection(); app.UseExceptionHandler("/Home/Error"); app.UseCookiePolicy(); } app.UseStaticFiles(); app.UseSession(); -------------------------------appsetting.json-------------------------------------------- "AppSettings": { "SessionTimeout": "40" } ---------------------------------------------------------------------------------------- Added Microsoft.AspNetCore.Session Package in application and also add below code .csproj file of the application. <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" /> </ItemGroup> # **2.IIS Changes** I.Changes server and application both session timeout to 40 mins. II.Set idle timeout to 40 minutes in application pool properties/performance for both end ( server and application). # **2.web.config Changes** <system.web> <pages viewStateEncryptionMode="Always" /> <customErrors defaultRedirect="Error.aspx" mode="RemoteOnly" /> <httpRuntime enableVersionHeader="false" requestPathInvalidCharacters="<,>,",',&,*,%,:,\" /> <httpCookies httpOnlyCookies="true" requireSSL="true" sameSite="Strict" domain="uat-fdcore.mfeka.com" /> <sessionState mode="InProc" timeout="40" /> <!--<machineKey validation="AES" />--> </system.web> I am still getting a session timeout at 20 minutes. Is there anything else I need to do?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)