We'll create a new ASP.NET Core Web project and add the required libraries to use cookies to hold authenticated user information in it:
- Let's create a new ASP.NET Core web project and configure it using cookie authentication:
dotnet new web -n CookieAuthenticationSample dotnet add package Microsoft.AspNetCore.Authentication.Cookies dotnet restore
- Now we need to add the following line in the Startup.cs file before the app.UseMvc() or app.UseMvcWithDefaultRoute() lines in the Configure() method:
app.UseAuthentication();
- We also need to add the following line in ConfigureServices() method, before the services.AddMvc() line, as follows:
services.AddAuthentication("CookieAuthenticationScheme") .AddCookie("CookieAuthenticationScheme", ...