In this article I will explain with an example, how to set custom Session Timeout in ASP.Net Core (.Net Core 8).
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();
Downloads
Other available versions