Skip to content

REST Controller method configuration

Ushakov Michael edited this page Jul 2, 2026 · 4 revisions

Introduction

This page contains brief information about how to configure presence a set of a default methods in a custom Controller.

Configuration

There are 3 types of Base Controllers:

Every application controller derives from one of these base controllers. To switch one or more methods use AllowedOperation attribute, consider we are having CRUD ProfileController that must have only a Read, Create and Update operations, example below shows how to configure your controller:

    [AllowedOperation(ControllerOperation.Read | ControllerOperation.ReadOne | 
                      ControllerOperation.Create  | ControllerOperation.Update)]
    public sealed class ProfileController : BasicCrudController<ProfileDto, ProfileEntity, int, EmptyAdditionalFilters>
    {
        public ProfileController(ProfileManager manager)
        {
            Manager = manager;
        }
    }

To make this feature work, a AllowedOperationsConvention MUST be passed to the AddControllers extension method in your Startup:

services.AddControllers(options =>
{
    options.Conventions.Add(new AllowedOperationsConvention());
});

Calling endpoints that were not included by the attribute result with the `MethodNotAllowed` status code

This configuration also affects OpenAPI Exploration, see: Profile does not contain DELETE method

Clone this wiki locally