Using cookie middleware without ASP.NET Core Identity

If you want to use your own data store and login controls to authenticate a user, Cookie middleware is the best choice. Cookie middleware serializes the user principal into an encrypted cookie and it uses that cookie to validate users on every request. The user principal can be retrieved by calling the HttpContext.User property.

Cookie middleware can be used by adding a NuGet package named Microsoft.AspNetCore.Authentication.Cookies and the following code snippet in the Configure method in the Startup class:

    CookieAuthenticationOptions options = new         CookieAuthenticationOptions();     options.AuthenticationScheme = "CookiesMiddlewareAuth";     options.LoginPath = "/Account/Login";  options.AccessDeniedPath ...

Get Enterprise Application Architecture with .NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.