liveBook · Manning

IPageRouteModelConvention

As explained in ASP.NET Core in Action, 3e

IPageRouteModelConvention is an ASP.NET Core interface for modifying route templates and route metadata while Razor Page models are being constructed.

IPageRouteModelConvention lets an ASP.NET Core Razor Pages application customize route templates while page route models are constructed. Registering a convention can rewrite routes or add routes automatically for every Razor Page. section 14.6

Prefix every page route

A custom convention can combine the prefix "page" with each selector's existing template. A page at Pages/Privacy.cshtml, normally reached as "Privacy", can then also be reached as "page/Privacy". Register the convention through AddRazorPagesOptions and its Conventions collection. section 14.6

Choose the convention mechanism that matches the customization:

  • Use AddPageRoute when one page needs an additional route without replacing its default route. section 14.6
  • Use IPageRouteModelConvention for application-wide route rewriting or automatic route creation, including localized URL patterns. section 14.6

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains route-model selectors, template rewriting, and registration, with a prefixing implementation.
Examples
Demonstrates prefixing every route with "page" and adding an alternative route to one page.
What it assumes
Assumes familiarity with Razor Pages and route templates while showing convention registration explicitly.
What you can do after
Build it from scratch by implementing Apply and registering the convention through AddRazorPagesOptions.
How it connects
Connects Razor Pages routing with AddPageRoute, IPageApplicationModelConvention, and IPageHandlerModelConvention.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.