Open Closed

RequiresFeature attribute not working on Blazor WASM Pages #8481


User avatar
0
BenS-FreshRF created
  • ABP Framework version: v8.3.2
  • UI Type: Blazor WASM
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

I'm applying the RequiresFeature attribute to a Blazor WASM Page to prevent pages and components from loading if they do not have the appropriate feature, but it isn't working. I've tried it on both the Razor page and on the Code Behind partial class but neither are working.

The Features documentation at https://abp.io/docs/latest/framework/infrastructure/features states that it only works on dependency injected services but makes an exception for Razor pages and controllers, but there is no mention of support for Blazor components.

Checking the feature using the IFeatureChecker service works fine on other methods.


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I'm applying the RequiresFeature attribute to a Blazor WASM Page to prevent pages and components from loading if they do not have the appropriate feature, but it isn't working. I've tried it on both the Razor page and on the Code Behind partial class but neither are working.

    Please share your component code to reproduce the problem.

    Thanks.

  • User Avatar
    0
    BenS-FreshRF created

    Blazor Razor Page - TestPage.razor

    @page "/testpage"
    
    @using Volo.Abp.Features
    
    @attribute [Authorize(Permissions.Pages.TestPage)]
    @attribute [RequiresFeature(Features.Pages.TestPage)]
    
    < div > This is a test page < /div >
    

    or Blazor Code Behind - TestPage.razor.cs

    using System;
    using Volo.Abp.Features;
    
    namespace Pages
    {
        [RequiresFeature(Features.Pages.TestPage)]
        public partial class TestPage {
            protected override async Task OnInitializedAsync()
            {
                // If I put in the FeatureChecker here it works but the page is still half rendered
                // Would be much better if it worked the same way as the [Authorize] attribute
            }
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks. I will confirm this.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have confirmed the FeatureInterceptor/@attribute [RequiresFeature(Features.Pages.TestPage)] will skip the type that inherits from ComponentBase.

    So you have to use code to check the feature.

    Thanks.

  • User Avatar
    0
    BenS-FreshRF created

    Is there a better place to check the Features than inside the OnInitialized event handlers? Doing it in there results in a half-rendered page before it breaks rather than a nice error message like when using the [Authorize] attribute.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think you can only do the feature check in the OnInitialized method.

  • User Avatar
    0
    BenS-FreshRF created

    Well that is disappointing.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Sorry for that.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09