title: NET Core 5 How to override an action on a controller
body: <p>Let's imagine I have a &quot;<em>platform</em>&quot; with some basic features. It has its own set of controllers with actions delivered as a class library. For example, let's name it as <code>CartController</code> with <code>Order</code> action, as a result, API URL will be <code>Cart/Order</code>.</p>
  <p>For some reason, I want to extend logic in Order process, I added <code>MyCartController</code> with <code>Order</code> action in my project where I reference the <em>platform</em>. Now I need to set up the app to use my custom action instead of the original one.</p>
  <p>In ASP MVC 5 (based on .NET Framework) I can do it as follows</p>
  <pre><code>public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          var route = new Route(&quot;Cart/Order&quot;, new RouteValueDictionary(new Dictionary&lt;string, object&gt;
          {
              { &quot;action&quot;, nameof(MyCartController.Order) },
              { &quot;controller&quot;, nameof(MyCartController).Replace(&quot;Controller&quot;, &quot;&quot;) }
          }), new MvcRouteHandler());
  
          routes.Insert(RouteTable.Routes.Count - 2, route);
      }
  }
  </code></pre>
  <p>and then call it from Startup as</p>
  <pre><code>public override void Configuration(IAppBuilder builder)
  {
      RouteConfig.RegisterRoutes(RouteTable.Routes);
  }
  </code></pre>
  <p>and it worked well.</p>
  <p>But after migration to .Net Core 5, it stopped working.
  In Startup, I added</p>
  <pre><code>public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
          app.UseRouting();
          app.UseEndpoints(endpoints =&gt; 
          {
              endpoints.MapControllerRoute(&quot;MyCartOrder&quot;, &quot;Cart/Order&quot;, new { controller = nameof(MyCartController).Replace(&quot;Controller&quot;, &quot;&quot;), action = nameof(MyCartController.Order) });
          });
  }
  </code></pre>
  <p>with no luck. It looks like they broke something helpful here <a href="https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/Routing/ControllerActionEndpointDataSource.cs#L100" rel="nofollow noreferrer">https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/Routing/ControllerActionEndpointDataSource.cs#L100</a></p>
  <p>I tried to decorate my controller with <code>Route(&quot;Cart&quot;)</code> attribute and <code>HttpPost(&quot;Order&quot;)</code> with <code>AmbiguousMatchException: The request matched multiple endpoints</code> exception.</p>
  <p>I have no idea of how to override it then.</p>
  <p>So my question is: <strong>How to override the route to use my action on my controller in .Net Core 5?</strong> What is the equivalent of routes.Add from .Net 4.8 which works for URL matching but not only for links generation?</p>
  <p>Any thoughts and ideas will be appreciated.</p>