dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.58k stars 25.3k forks source link

Clarification on the role of Filter Attribute when used in Folders #22990

Open Ponant opened 3 years ago

Ponant commented 3 years ago

This tutorial is great but there is something I am not sure if it is OK or bad practice. I naively took the Filter Attribute and tried to use it globally in the Movies,

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages(options =>
    {
        options.Conventions.AddFolderApplicationModelConvention(
            "/Movies",
            model => model.Filters.Add(new AddHeaderAttribute("Author", "Rick")));
    });
}

And it works! Is that OK, and if so what would be the problem, if any, or limitation? I am happy to update the docs to mention this, if that is an OK practice.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Ponant commented 3 years ago

Motivation behind this question: I already have a ResultFilterAttribute with logic in it that can be applied on indivudual pages. Implementing the same logic on a folder will require me to virtually duplicate the logic, hence the question.

Rick-Anderson commented 2 years ago

@mkArtakMSFT please assign a reviewer.