liveBook · Manning

Pages folder

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

The Pages folder is the application directory containing Razor Pages files that define independently addressable web pages.

The Pages folder contains the Razor Pages files that define the independently addressable pages of a web application, such as Home and Privacy. section 13.1.1

Use the folder structure to understand how Razor Pages become web endpoints:

  • Place a page such as Pages/Products/View.cshtml in the Pages directory. section 14.3
  • ASP.NET Core creates a route template from the page path relative to Pages, excluding the .cshtml extension. section 14.3
  • Pages/Products/View.cshtml therefore maps to the route Products/View, which handles requests such as /products/view. section 14.3
  • An Index.cshtml page also responds to the route without the Index suffix, such as ToDo for Pages/ToDo/Index.cshtml. section 14.3

A page and its route

Create Pages/Products/View.cshtml. After Razor Pages routing is mapped, a request to /products/view selects that page; the framework then invokes an appropriate page handler. section 14.3

Figure 13.4 Comparing the project structure of a minimal API app with a Razor Pages app. The Razor Pages app contains all the same files and folders, as well as the Pages folder for the Razor Page definitions and the wwwroot file for static files that are served directly to the browser.
CH13_F04_Lock3

Compare the Pages folder with the project structure of a minimal API application. section 13.1.1

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

How deep it goes
Explains path-based routing and endpoint selection, but defers detailed page-handler selection.
Examples
Uses Home, Privacy, Products/View, and ToDo/Index pages to demonstrate files, URLs, and route conventions.
What you can do after
Build pages in the Pages directory and predict their default URLs from their file paths.
How it connects
Connects Razor Pages with routing, route templates, PageModel handlers, and the ASP.NET Core middleware pipeline.

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.