Skip to content

Routing - cannot change precedence of DynamicRouteValueTransformer #45175

@razzemans

Description

@razzemans

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This is related to #29594

For our applications, we developed a CMS which implies that most of our routes are dynamic and determined during runtime - users can create and publish pages. For this I created a custom DynamicRouteValueTransformer which would check if a page for a given url exists in the database. Typically we would configure the routing in our applications like this:

app.UseEndpoints(endpoints =>
{
	endpoints.MapDynamicControllerRoute<CmsRoute>("{**slug}");
	endpoints.MapDefaultControllerRoute();
});

This worked like a charm, in .NET 5.0. If we had a route configured using attribute routing, that route would match and the CmsRoute would not be invoked. I believe since updating to .NET 6.0, the DynamicRouteValueTransformer is always invoked, just as described in the #29594. I am not sure about the solution though.

Mapping to a fallback controller doesn't work, since we have defined custom Controllers for certain page types (a page of type Foobar in the Cms is eventually mapped, in the DynamicRouteValueTransformer, to the FoobarController by setting the correct values in the RouteValueDictionary). I would somehow need to invoke a FoobarController from the FallbackController, which I am not even sure is possible (a redirect obviously is not desirable).

I came across #34316 which mentions using the ApplicationModelProvider. While I haven't researched it yet, it sounds like quite some refactoring to make it working again. Moreover, I am concerned about performance issues, since pages may be created at runtime, can be scheduled to go live at certain points in time, so it sounds like I would have to invoke the IChangeToken quite often (e.g. every 10 seconds, which I am not sure is desirable).

I was actually hoping I am missing a small change I can make to make the DynamicRouteValueTransformer working again so it is not invoking for endpoints configured using conventional routes. Also, after reading a lot about the routing I still don't understand why a catch-all route like {**slug} is considered to have more precedence than a controller endpoint with a [Route("/xyz")] defined as endpoint.

.NET Version

6.0+

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-routingquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions