liveBook · Manning

Page filter

As explained in Pro ASP.NET Core 7, Tenth Edition

IPageFilter is the ASP.NET Core interface for synchronous Razor Pages filters that participate in page-handler selection and execution.

A page filter is an ASP.NET Core filter for Razor Pages. It changes a request before a page-handler method runs or changes the result afterward, and it can be attached to specific endpoints for reuse. section 30.3 section 30.8

IPageFilter defines three synchronous callbacks. OnPageHandlerSelected runs after handler selection but before model binding; OnPageHandlerExecuting runs after binding and before the handler; OnPageHandlerExecuted runs after the handler but before result processing. section 30.4.4

Changing a handler argument

A filter can implement IPageFilter and alter bound arguments before the handler runs: `public void OnPageHandlerExecuting(PageHandlerExecutingContext context) { if (context.HandlerArguments.ContainsKey("message1")) context.HandlerArguments["message1"] = "New message"; }`. Applying `[ChangePageArgs]` to the MessageModel page makes the handler receive the replacement value.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines synchronous lifecycle callbacks, context properties, short-circuiting, and an argument-mutation example; defers implementation internals.
Examples
Uses ChangePageArgs on the Message page to replace the message1 handler argument before execution.
What it assumes
Assumes familiarity with ASP.NET Core Razor Pages, handler methods, model binding, and action results.
What you can do after
Apply it via ASP.NET Core to modify handler arguments, short-circuit requests, or inspect results and exceptions.
How it connects
Connects Razor Pages with filter pipelines, model binding, page handlers, action filters, middleware, and action results.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.