Custom cookie authentication in Blazor SSR + Interactive Server for .NET 8
You don’t use Identity or Entity Framework. You just want the basics.
In this article, I will be showing a very simple example of how to set up cookie authentication.
Configuration
- Create the project (with defaults selected)
2. Add services to Program.cs
- The AddCascadingAuthenticationState() service takes care of providing authentication state across ALL render modes.
3. Change the route view component in Routes.razor to AuthorizeRouteView.
Testing
- Create a login page.
I made a simple form that checks if credentials match “Harry” and “Potter”. This page needs to be a static server rendered page.