How do I add an MVC filter programmatically to select routes?

1.1k Views Asked by At

In ASP.Net Core I know how to add the AuthorizeFilter to all routes programmatically, like this..

services.AddMvc(options =>
{
    options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
})

However, I would like to only select certain paths to do this to. How can I do this? I just need a way to enforce authentication at startup to select paths, without having to decorate every route manually with the attribute. Thank you.

0

There are 0 best solutions below