title: Dynamic routing in ASP.NET Core 3.1 when part of the url is already another route
body: <p>I'm trying to use <code>DynamicRouteValueTransformer</code> with <code>IEndpointRouteBuilder.MapDynamicControllerRoute</code> to dynamically map new routes. This is for pages that are added while the application is running.</p>
  
  <p>I'm doing:</p>
  
  <pre><code>endpoints.MapDynamicControllerRoute&lt;RouteValueTransformer&gt;("{**slug}");
  </code></pre>
  
  <p>to catch <em>all</em> urls that don't already have a route assigned, so that <code>RouteValueTransformer</code> can try to find one when necessary. By putting a breakpoint inside the <code>RouteValueTransformer.TransformAsync</code> method, I can see when it runs. If you just type any nonsense url in, it will enter the method as expected. For a url that doesn't have a route assigned, but an earlier part of the url <em>does</em>, it <em>won't</em> enter the method, as it seems to think it already has a route, but then it obviously gives a 404 error. </p>
  
  <p>For example, if after the above line I do</p>
  
  <pre><code>endpoints.MapControllerRoute(
     name: "test",
     pattern: "category/product1",
     defaults: new { controller = "Home", action = "Index" });
  </code></pre>
  
  <p>and then try to browse to "category/product2", I think it should enter the <code>TransformAsync</code> method to try and find a route, but it doesn't, and it gives a 404. If you change "category" to something else, it <em>will</em> enter the method.</p>
  
  <p>I'm not sure if this is expected behaviour, a bug, or if I'm using the "pattern" parameter wrong, or maybe {**slug} wrong?</p>
  
  <h2>To reproduce</h2>
  
  <p>It's very easy to reproduce. Create a new ASP.NET Core 3.1 web application. Add </p>
  
  <pre><code>app.UseEndpoints(endpoints =&gt;
  {
      var defaults = new { controller = "Home", action = "Index" };
      endpoints.MapControllerRoute(name: "test", pattern: "category/product1", defaults: defaults);
      endpoints.MapDynamicControllerRoute&lt;RouteValueTransformer&gt;("{**slug}");
  });
  </code></pre>
  
  <p>to the end of <code>Startup.Configure</code>, </p>
  
  <pre><code>services.AddSingleton&lt;RouteValueTransformer&gt;();
  </code></pre>
  
  <p>to <code>Startup.ConfigureServices</code>,
  and </p>
  
  <pre><code>public class RouteValueTransformer : DynamicRouteValueTransformer
  {
      public override async ValueTask&lt;RouteValueDictionary&gt; TransformAsync(HttpContext httpContext, RouteValueDictionary values)
      {
          return values;
      }
  }
  </code></pre>
  
  <p>and set a breakpoint on <code>return values;</code> to see when it runs.</p>
  
  <h2>What else I've tried</h2>
  
  <p><code>endpoints.MapDynamicControllerRoute&lt;RouteValueTransformer&gt;("{one}/{two}");</code> - also doesn't enter method.</p>
  
  <p>Looking through documentation. There isn't much on <code>DynamicRouteValueTransformer</code> <a href="https://github.com/aspnet/AspNetCore.Docs/issues/12997#" rel="nofollow noreferrer">(yet)</a> unfortunately so I've found it quite difficult.</p>
  
  <h2>Update</h2>
  
  <p>I'm starting to think that it <em>is</em> mostly likely a bug, so I've raised <a href="https://github.com/dotnet/aspnetcore/issues/18688" rel="nofollow noreferrer">this Github issue</a></p>