Friday, April 17, 2020

A lot of the new .NET Core 3.1.4 routing tricks do not hydrate a route at IRouteBuilder off of IApplicationBuilder.

app.UseEndpoints(endpoints =>
{
   endpoints.MapControllerRoute(

 
 

...won't work! Fish out the route like so:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
namespace Cms.Web.Services.Models
{
   public class DeRouting
   {
      IApplicationBuilder app;
      public DeRouting(IApplicationBuilder app)
      {
         this.app = app;
      }
      
      public IRouteBuilder GetRoutes()
      {
         IRouteBuilder routes = new RouteBuilder(app);
         routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
         return routes;
      }
   }
}

No comments:

Post a Comment