title: How to dynamically route request to a specific controller and action with the original request paths as parameters
body: <p>I am unable to find any documentation/details on the format of the middleware endpoints pattern field. Or endpoints at all really. Only examples of common use case scenarios for routing. </p>
  
  <p>What I'd like to do is accept a request like:</p>
  
  <p><strong><code>example.com/anything1/anything2</code></strong></p>
  
  <p>and send it forward to:</p>
  
  <p><strong><code>example.com/Home/Display?var1=anything1&amp;var2=anything2</code></strong></p>
  
  <p><strong>The browser should display the original request and not change.</strong></p>
  
  <p>My end goal is to return the <code>home</code> controller's layout with the <code>view</code> getting data from a database.</p>
  
  <p>I've been throwing random data at it to see what breaks it but not successful at understanding what works.</p>
  
  <pre><code>pattern: "{custompath}/{custompage}");
  
  app.UseEndpoints(endpoints =&gt;
  {
      endpoints.MapControllerRoute(
          name: "default",
          pattern: "{controller=Home}/{action=Index}/{id?}");
      endpoints.MapControllerRoute(
          name: "notDefault",
          pattern: "{area:exists}/{controller=Content}/{action=Index}/{id?}");
  });
  </code></pre>
  
  <p>This is the current default setup that works with my areas and controllers but I don't fully understand why either.</p>
  
  <p><strong>Update</strong>
  The migration article from asp.net core 2.2 to 3 says that "Endpoint Routing supports the same route pattern syntax and route pattern authoring features as IRouter". 
  <a href="https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&amp;tabs=visual-studio#mvc-service-registration" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&amp;tabs=visual-studio#mvc-service-registration</a></p>
  
  <p>There are no links to the expected syntax but I've found some old articles that have information. While being helpful they are still incomplete and/or inaccurate. When applying the logic I have found bugs. This was the most informative.
  <a href="https://aspnetcore.readthedocs.io/en/stable/fundamentals/routing.html" rel="nofollow noreferrer">https://aspnetcore.readthedocs.io/en/stable/fundamentals/routing.html</a></p>
  
  <p>Some routes work but break when I add others. For instance, this route based on the article above should only be accepted when someone types "Account" as the first parameter but instead when requesting with no paths or arguments it manipulates the request to include Account the next route's controller default. But then returns the last route as expected.</p>
  
  <p>When requesting <a href="https://localhost:port" rel="nofollow noreferrer">https://localhost:port</a></p>
  
  <pre class="lang-cs prettyprint-override"><code>endpoints.MapControllerRoute(
      name: "account",
      pattern: "Account/{controller=Dashboard}/{action=Overview}",
      defaults: new { area = "Account" });
  endpoints.MapControllerRoute(
      name: "manage",
      pattern: "Manage/{controller=Content}/{action=Index}",
      defaults: new { area = "Manage" });
  endpoints.MapControllerRoute(
      name: "default",
      pattern: "",
      defaults: new { controller = "Content", action = "Display", path = "Public", page = "Index" });
  </code></pre>
  
  <p>it manipulates the request to <a href="https://localhost:port/Account/Content/" rel="nofollow noreferrer">https://localhost:port/Account/Content/</a> 
  and with contents from <a href="https://localhost:port/Content/Display/" rel="nofollow noreferrer">https://localhost:port/Content/Display/</a> </p>
  
  <p>I was expecting that when I didn't type in Account or Manage it would fall through to the blank route and stop there. But it seems that after it gets there it does some other stuff. Half of what I want is accomplished lol.</p>
  
  <p><strong>Latest Update</strong>
  Currently, I have this working with minimal bugs. Conceptually when making these I imagined that the pattern was the structure that exists in my app (controller > action > param, which is backward from what I originally imagined. (that the pattern was what the user request is*)</p>
  
  <pre class="lang-cs prettyprint-override"><code>    endpoints.MapControllerRoute(
                      name: "Public",
                      pattern: "{page}",
                      defaults: new { controller = "Content", action = "Display", path = "Public" });
                  endpoints.MapControllerRoute(
                      name: "Default",
                      pattern: "{path=Public}/{page=Index}",
                      defaults: new { controller = "Content", action = "Display" });                
                  endpoints.MapControllerRoute(
                      name: "Controllers",
                      pattern: "{controller}/{action}/{id?}");
  </code></pre>
  
  <p>notes:</p>
  
  <p>"areaName:" adds the name in quotes to the request.
  "defaults:" manipulates the request. I was able to inject a controller and action.</p>
  
  <p>The other thing to note is that these endpoints affect the generated routes for links that use asp-*</p>