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

How to create custom attributes to reference them in a page.razor, like @page etc

$
0
0

Project Structure: Blazor Automode, .Net 8

To create a page in a blazor project you use:

@page "yourUrl"

I want to create my own page attribute for the exact permissions to be able acess a page like:

@page "/user/crud"//this line below is what i believe it would be, but currently does not work@permissions "[userRead, userWrite]"

Does exists a way to make it work? If so, how?

I've tried researching but the only seggestion i found was:

using System;[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]public class MyCustomAttribute : Attribute{    public string Permissions { get; set; }}
@MyCustomAttribute(Permissions = "PermissionToWrite")@page "/my-page"<h1>Welcome to my custom page!</h1>

But basically does not work.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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