ASP.NET Core MVC Interview Question #94

What is a resource filter?

Advanced Routing, Filters, Areas & Application Structure Mid-Level Intermediate

Quick Interview Answer

A resource filter runs after authorization and surrounds much of the remaining MVC pipeline. Because it executes before model binding, it can be useful for concerns such as caching or short-circuiting expensive MVC processing.

Detailed Explanation

A resource filter runs after authorization and surrounds much of the remaining MVC pipeline. Because it executes before model binding, it can be useful for concerns such as caching or short-circuiting expensive MVC processing.

Resource filters should be used carefully because their early position gives them broad influence over request processing.

Code Example

public sealed class ExampleResourceFilter
    : IResourceFilter
{
    public void OnResourceExecuting(
        ResourceExecutingContext context)
    {
    }

    public void OnResourceExecuted(
        ResourceExecutedContext context)
    {
    }
}