Setting the file. One moment.
Subchapter 1.12
references/ui-razor-pages.mdMarkdown2 KBView on GitHub
Prefer Razor Pages when requests naturally map to pages, forms, and page-level handlers. This is a strong default for internal tools, CRUD apps, account flows, and admin surfaces.
Enable Razor Pages with:
builder.Services.AddRazorPages();app.MapRazorPages();Use the @page directive to turn a .cshtml file into an endpoint. Keep request logic in the paired PageModel class when the page is more than trivial.
Pages/Index.cshtml maps to /Pages/Store/Index.cshtml maps to /StoreOnGet, OnPost, and named handlers for request processingDo not rely on per-handler authorization with Razor Pages. Microsoft explicitly recommends using MVC controllers when different handlers on the same logical surface need different authorization behavior.
Preferred responses to that limitation: