Multiple Routes For a Razor Page
See original GitHub issueRazor Pages Feature Request
Asp.Net MVC supports multiple routes per action:
[Route("something/{id}")]
[Route("somethingelse/{id}")]
public ActionResult Index(int id)
I would love the ability for Razor Pages to support something like this at the page level. Something like:
@page {"something/{id}","somethingelse/{id}"}
Or support adding Route attributes to PageModels?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Multiple routes to the same razor page
I've got a razor page in my Asp.Net Core 3.1 website called SignupAndApply. It's effectively a copy and paste of the register identity...
Read more >Routing in Razor Pages
Routing is the system that matches URLs to Razor pages. Like most page-centric frameworks, the primary routing system in ASP.NET Razor Pages ......
Read more >Multiple Routes For a Razor Page · Issue #10691
Razor Pages Feature Request Asp.Net MVC supports multiple routes per action: [Route("something/{id}")] [Route("somethingelse/{id}")] public ...
Read more >Razor Pages route and app conventions in ASP.NET Core
Learn how to use page route and app model provider conventions to control page routing, discovery, and processing in Razor Pages apps.
Read more >5 Mapping URLs to Razor Pages using routing
Routing is the process of mapping an incoming request URL to a Razor Page that will execute to generate a response. You can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Using
AddPageRoutemakes it the default route for link generation. Essentially any other route associated with that page do not participate in link generation. There’s a bug in MVC where callingAddPageRoutemultiple times prevents previously added route from being used for link generation. That said, you could write a convention that configures the routes for the page. Here’s what theAddPageRoutedoes under the hood:https://github.com/aspnet/AspNetCore/blob/b93bc433db66175d2b07b128ec9990f7a4dd7e1b/src/Mvc/Mvc.RazorPages/src/DependencyInjection/PageConventionCollectionExtensions.cs#L470-L490
I have a scenario where I cannot get that to work:
Page:
Pages/Production/details.cshtml@pagedirective is blankAdded this convention:
options.Conventions.AddPageRoute("/production/details", "production/{id}/details");In the browser:
"/production/details"works"/production/100/details"worksThe issue is with tag helpers:
<a asp-page="/production/details" asp-route-id="100">works<a asp-page="/production/details">blank href