liveBook · Manning

Chapter 21: The MVC and Razor Pages filter pipeline

What you will learn in chapter 21 of ASP.NET Core in Action, 3e

Introduces the MVC and Razor Pages filter pipeline as an internal, middleware-like mechanism for cross-cutting concerns and previews how the chapter explores its types, use, and ordering.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the MVC and Razor Pages filter pipeline as an internal, middleware-like mechanism for cross-cutting concerns and previews how the chapter explores its types, use, and ordering.

Key terms: filter pipeline, action invocation pipeline, cross-cutting concerns, authorization filters, MVC filter pipeline, middleware pipeline, minimal API endpoint filter pipeline, filters, filter types, custom filter

21.1 Understanding the MVC filter pipeline

This section introduces the MVC filter pipeline as MVC-specific hooks for running shared code at defined points during a controller request.

Key terms: MVC filter pipeline, filters, cross-cutting concerns, action method, authorization filters, resource filters, action filters, exception filters, result filters, model binding

21.2 The Razor Pages filter pipeline

This section compares the Razor Pages filter pipeline with MVC and explains how page filters run at three distinct points around handler execution.

Key terms: authorization filters, resource filters, exception filters, result filters, action filters, page filters, page handler selection, model binding, validation, IActionResult

21.3 Filters or middleware: Which should you choose?

This section compares MVC/Razor Pages filters with middleware and gives criteria for choosing the more appropriate scope and capabilities.

Key terms: middleware pipeline, filter pipeline, short-circuiting, cross-cutting concerns, resource filters, action filters, EndpointMiddleware, controller action, Razor Page handler, ModelState

21.4 Creating a simple filter

This section shows how to implement synchronous or asynchronous MVC and Razor Pages filters, using resource filters to illustrate their lifecycle and pipeline contexts.

Key terms: IAuthorizationFilter, IAsyncAuthorizationFilter, IResourceFilter, IAsyncResourceFilter, IActionFilter, IAsyncActionFilter, OnResourceExecuting, OnResourceExecuted, ResourceExecutingContext, ResourceExecutedContext

21.5 Adding filters to your actions and Razor Pages

This section explains how filter scope controls which MVC actions and Razor Pages a filter affects, from a single action to the entire application.

Key terms: scope, action method, controller, Razor Page, global filter, filter attribute, LogResourceFilter, controller scope, PageModel, page handler

21.6 Understanding the order of filter execution

This section introduces how the execution order of multiple MVC or Razor Pages filters in the same pipeline stage is determined by scope and can be customized.

Key terms: filter pipeline, filter stage, resource filters, scope, filter execution order, action method pipeline, default order, customize the order

21.6.1 The default scope execution order

This subsection explains how filter scope determines the default before-and-after execution order for MVC actions and Razor Pages.

Key terms: resource filters, action filters, result filters, *Executing methods, *Executed methods, global scope, Razor Pages, global scope filters, Razor Page scope filters, PageHandlerSelected methods

21.6.2 Overriding the default order of filter execution with IOrderedFilter

This section explains how IOrderedFilter overrides scope-based filter ordering by assigning numeric Order values within each filter-pipeline stage.

Key terms: IOrderedFilter, Order, filter pipeline, scope, Order = 0, ASP.NET Core filters

21.7 Summary

This summary recaps how MVC and Razor Pages filters provide stage-specific hooks for cross-cutting concerns, including their execution patterns, scopes, and ordering.

Where this is used later

Concepts explained in this chapter

← Chapter 20: Creating an HTTP API using web API controllers Chapter 22: Creating custom MVC and Razor Page filters →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.