-
Book Overview & Buying
-
Table Of Contents
Blazor WebAssembly by Example - Third Edition
By :
The Authorize attribute is used at the page level to require authorization. The following component demonstrates the Authorize attribute:
Secure.razor
@page "/secure"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<h2>Secure Page</h2>
Congratulations, you have been authenticated!
When an unauthenticated user tries to navigate to a page with the Authorize attribute, the application responds according to the behavior defined in App.razor.
You can require authentication for every page by adding the Authorize attribute to the _Imports.razor file. However, if you do that, you must add the AllowAnonymous attribute to the authentication component or your users won't be able to log in.
The Authorize attribute supports both role-based and policy-based authorization. If the user has been authenticated and they try to navigate to a page that includes either role-based or policy-based authorization, and they...