How to authorize Blazor server app according to role by folder path?

Zang-Ho Bae 26 Reputation points
2021-01-12T03:48:48.953+00:00

In a Razor page app or a MVC app, I can authorize multiple page by AuthorizeAreaFolder method.
In Blazor project, I don't find like this method.
I wanna authorize multiple Blazor page according to role by folder path.
How can i this?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,203 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,401 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiadong Meng - MSFT 121 Reputation points
    2021-01-13T03:05:42.213+00:00

    Hi @Zang-Ho Bae ,

    It can work in Blazor servert app. Configure it in startup.cs like this:

        services.AddRazorPages(options =>  
            // authenticated user only  
            options.Conventions.AuthorizeAreaFolder("Admin", "/")  
      
            // user with certain roles only  
            //options.Conventions.AuthorizeAreaFolder("Admin", "/", "AdminRoles")  
            );  
    

    Best Regards,

    Jiadong Meng


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.