Open Closed

Feature/Role based access to the components #9099


User avatar
0
Karthigeyan created

Hi Team,

In the application we have multiple components at UI level and respective API/app services (where the services can be restricted at the permission level). But we are looking for solution/approach where the permission/feature where it can be applied at the login time of the user and based on that it can be restrict to the specific components.

Thanks

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    If I understood correctly, you're looking for a way to check the user's permissions (or features), and based on that, control which UI components should be visible or accessible. Is that right?

    If so, here's a common and recommended approach:

    For menu items:

    {
      path: '/authors',
      name: '::Menu:Authors',
      parentName: '::Menu:BookStore',
      layout: eLayoutType.application,
      requiredPolicy: 'BookStore.Authors',
    }
    

    For UI components:

      <button *abpPermission="'BookStore.Authors.Create'" id="create" class="btn btn-primary" type="button" (click)="createAuthor()">
                <i class="fa fa-plus me-1"></i>
                <span>{{ '::NewAuthor' | abpLocalization }}</span>
              </button>
    

    If you want to check whether a specific feature is enabled or disabled and render something accordingly, you can check this document.

    For AppService methods:

    [Authorize(BookStorePermissions.Authors.Delete)] 
    public async Task DeleteAsync(Guid id)
    {
        //continue to the normal flow...
    }
    

    or

    public async Task CreateAsync(CreateAuthorDto input)
    {
        var result = await AuthorizationService
            .AuthorizeAsync("Author_Management_Create_Books");
        if (result.Succeeded == false)
        {
            //throw exception
            throw new AbpAuthorizationException("...");
        }
    
        //continue to the normal flow...
    }
    

    If I misunderstood your question or you're trying to do something else, feel free to give a bit more detail.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.