Tag: Programming

  • C# .net Core MapRoute Not Working?

    Recently I faced a challenge while trying to programatically register routes on a .net core MVC application. The following was my code.

    app.UseMvc(routeBuilder =
    {
    routeBuilder.MapRoute(
    name: "example-route",
    template: "example",
    defaults: new { controller = "ExampleController", action = "ExampleAction" }
    );
    });

    Once the route was registered, I tried navigating to it and I kept getting a 404. Was breaking my head as to why this was happening. Finally found the issue.

    The controller name cannot have the post-fix Controller, the following change made the trick.

    app.UseMvc(routeBuilder =
    {
    routeBuilder.MapRoute(
    name: "example-route",
    template: "example",
    defaults: new { controller = "Example