Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

C# Blazor .NET 9: automatically collect all application Policies

$
0
0

I use .NET 9 and blazor, ASP.NET Core Identity - role, policy, claim.To differentiate access on pages and components, the code is using policies - like this:

@attribute [Authorize(Policy("Counter.Page")] <AuthorizeView Policy = "Counter.IncrementCount"><Button> Increment </button></AuthorizeView>

When launching the application, I would like to automatically collect all policies, as I did before in MVC controllers / actions using reflection. After that, I create an array of claims based on the policies found.

I manage to find the entire list of policies in the @attribute [Authorize(Policy("Counter.Page")], but I can't get to the policy inside the components

<AuthorizeView Policy = "Counter.IncrementCount">

I understand this is difficult/impossible, since the reflection assembly is a list of classes, not their instances.

All I could think of to make the task easier was to create my own attribute which duplicates the policy on

<AuthorizeView Policy = "Counter.IncrementCount"> 

and add it to pages with access restrictions.

@attribute [PolicyAttributes("Counter.IncrementCount", "Counter.DecrementCount")]

I tried wrapping the default code

<AuthorizeView Policy = "Counter.IncrementCount"><Button> Increment </button></AuthorizeView>

around my component

<AuthorizePolicy Policy = "Counter.IncrementCount"><Button> Increment </button></AuthorizePolicy>

But I couldn't figure out what to do with it.

Maybe there is some way to automatically collect all policies?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>