In this article I will explain with an example, how to set custom Session Timeout in ASP.Net Core (.Net Core 8).
Note: For enabling and configuring Session in ASP.Net Core (.Net Core 8), please refer my article .Net Core 8: Enable Session in ASP.Net Core.
 
 

Setting Session Timeout

In case you want to set the custom Session timeout value, you will need to set the IdleTimeout property which sets the Session timeout duration.
Note: The default Session Timeout in ASP.Net Core is 20 minutes.
 
var builder = WebApplication.CreateBuilder(args);
 
//Enabling MVC
builder.Services.AddControllersWithViews();
//Set Session Timeout. Default is 20 minutes.
builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(45);
});
 
var app = builder.Build();
app.UseSession();
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
 
app.Run();
 
.Net Core 8: Set custom Session Timeout in ASP.Net Core
 
Note: For more details on using Session in ASP.Net Core (.Net Core 8), please refer my article .Net Core 8: Using Session in ASP.Net Core.
 
 

Downloads



Other available versions