For the complete documentation index, see llms.txt. This page is also available as Markdown.

Disabled Action Handling

When an MVC controller or action is blocked because none of the features it specifies are enabled, a registered IDisabledFeaturesHandler will be invoked. By default, a minimalistic handler is registered which returns HTTP 404. This can be overridden using the IFeatureManagementBuilder when registering feature flags.

public interface IDisabledFeaturesHandler
{
    Task HandleDisabledFeature(IEnumerable<string> features, ActionExecutingContext context);
}

Example implementation

public class FeatureNotEnabledHandler : IDisabledFeaturesHandler
{
    public Task HandleDisabledFeatures(IEnumerable<string> features, ActionExecutingContext context)
    {
        var result = new ViewResult()
        {
            ViewName = "Views/Shared/FeatureNotEnabled.cshtml",
            ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
        };

        result.ViewData["FeatureName"] = string.Join(", ", features);

        context.Result = result;

        return Task.CompletedTask;
    }
}

Then register as singleton in startup.cs

Last updated