The cookie authentication mechanism sends a secure cookie with authorization info. Every request made from a client to a server contains that secure cookie, and the server-side application can identify the user from the secure cookie.
Note
An example project can be found at: https://github.com/polatengin/B05277/tree/master/Chapter17/1-CookieAuthenticationSample.
To work through this example, you need to create a simple ASP.NET Core 2.0 project and add some libraries in it.
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 theapp.UseMvc()
orapp.UseMvcWithDefaultRoute...