Search code examples
razorblazor.net-7.0authorize

Unrecognized attribute 'role' on child content element 'Authorized'


I'm getting the error from the title when i try to use the role attribute on the Authorized element in Blazor. It worked earlier this day. I haven't changed anything actively regarding this.

This is a minimalistic test razor compoment where it does't work.

<h3>Test</h3>

<AuthorizeView Roles="test,prod">
    <Authorized role="test">

    </Authorized>
    <Authorized role="prod">

    </Authorized>
</AuthorizeView>

@code {

}

Google didn't help me on that case. Any idea would be appreciated!

Environment: VS 2022 Blazor Win 10 .NET 7


Solution

  • Authorized does not work like this I'm afraid. The role property you are seeing is unrelated and can be added to most razor tags, and specifies the visual role of the element, and isn't associated with Authorization.

    If you want to have two separate views for test and prod I'd suggest simply having two AuthorizeView tags, like the following:

    <AuthorizeView Roles="test">
        <Authorized>
    
        </Authorized>
    </AuthorizeView>
    <AuthorizeView Roles="prod">
        <Authorized>
    
        </Authorized>
    </AuthorizeView>