Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 3 Razor pages app - Authorize all pages within an Area

I am trying to lock access to all the pages in selected Areas in my Razor Pages app. So far I have this sample structure

Areas

  • Account

    • Index.chtml
  • Business

    • Index.chtml

If I add

options.Conventions.AuthorizeFolder("/business", "/index"); 

to startup, it works on a per page basis, but I cant see any clear way to lock the entire Business folder. I've tried the folder based options mentioned here

https://learn.microsoft.com/en-us/aspnet/core/security/authorization/razor-pages-authorization?view=aspnetcore-3.0

but none seem to work. Is this even possible?

like image 737
Raj Avatar asked Nov 16 '19 15:11

Raj


People also ask

What is the difference between Razor view and Razor page?

The difference between them is that View Pages are Razor views that are used to provide the HTML representations (aka views) for services in much the same way View Pages work for MVC Controllers.

How do I navigate from one Razor to another page?

you can do it in the client side, in javascript. Also create an anchor a set the asp-controller and asp-action and there you redirect. Or create an anchor a and hard code the path.


1 Answers

So 10 seconds after asking, this works

options.Conventions.AuthorizeAreaFolder("business", "/");
like image 190
Raj Avatar answered Oct 12 '22 09:10

Raj