Securing markup areas
Sometimes, restricting access to an entire page can be too limiting. You might want to expose your landing page to everyone while fine-tuning the elements users see in the navigation menu. For example, authenticated users might have access to a back office feature that standard users cannot see despite viewing the same page. Blazor supports protecting specific markup areas with an AuthorizeView
component. The AuthorizeView
component allows you to control the visibility of content based on the user’s authentication state. It supports various states and works seamlessly with RenderFragment
objects, making it highly flexible and versatile.
Let’s leverage the AuthorizeView
component and add a status message visible only to authenticated users.
Getting ready
Before we add a protected status message to a component, do the following:
- In the server-side project, create a
Components
/Recipes
/Recipe03
directory – this will be your working...