Search⌘ K
AI Features

Securing Blazor WebAssembly Views

Discover how to secure Blazor WebAssembly views by enforcing authentication with the AuthorizeRouterView and [Authorize] attribute. Learn to configure automatic login redirects, manage unauthorized access, and apply role or policy-based restrictions within your ASP.NET Core Blazor apps.

In this lesson, we will learn how to enforce authentication on specific views in Blazor WebAssembly. The following playground will help us with this goal:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
Blazor WebAssembly app with the OpenID Connect flow

Note: Because we have to build two ASP.NET Core applications and populate the IdP database with the initial seed data, the build process is expected to take at least a few minutes.

If we launch this application, we will not be taken to the home page immediately. Instead, we will be redirected to the login page of ...