Setup Session for ASP.Net Web App

From TRCCompSci - AQA Computer Science
Revision as of 13:29, 16 October 2024 by Admin (talk | contribs) (Created page with "=Setting up Session for ASP.Net Core Web App= Using the nuget package manager you need to install `Microsoft.AspNetCore.Session`. The version I have used is 2.2.0. You can no...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Setting up Session for ASP.Net Core Web App

Using the nuget package manager you need to install `Microsoft.AspNetCore.Session`. The version I have used is 2.2.0.

You can now add the following code to your `program.cs` file:

builder.Services.AddDistributedMemoryCache();

builder.Services.AddSession(options =>
{
	options.IdleTimeout = TimeSpan.FromSeconds(10);
	options.Cookie.HttpOnly = true;
	options.Cookie.IsEssential = true;
});