Custom cookie authentication in Blazor SSR + Interactive Server for .NET 8

nedy
3 min readDec 11, 2023

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

  1. Create the project (with defaults selected)
Shows the default selections in Visual Studio 2022.

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

  1. 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.

--

--

nedy
nedy

Written by nedy

A nerd just wanting to share some advice or randomness + t.v. fanatic 📺 that may get too into fiction