From the course: ASP.NET Core Identity: Authentication Management

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Creating an authentication cookie

Creating an authentication cookie - ASP.NET Core Tutorial

From the course: ASP.NET Core Identity: Authentication Management

Start my 1-month free trial

Creating an authentication cookie

- To create an authentication cookie, which holds user information, we need to construct a claims principal. Then the user information is serialized and stored in a cookie. Let us go to our visual studio project and see how we can create a cookie. In our Auth 20 project, let us go to the controllers folder, and inside here to the Account Controller. Scroll down to the second login method, which takes the parameter, a login view model, and here we are going to create our cookie. So, in line 35, let us press enter and start creating our cookie. So, we said that we need to create a claims identity. For that, we write in here, var claims identity is equal to new claims identity, and then we import the necessary namespace, which is the system dot security dot claims. This object will take two parameters. The first parameter is going to be the claims array, so we can provide a couple of claims, and the second parameter is going to be our authentication scheme. So, for that I'll just write…

Contents