locked
301 redirect (list) RRS feed

  • Question

  • User-195907812 posted

    I am redirecting URLs using this rule format

    routes.MapRoute(
       name: "route_redirect_about",
       url: "/pages/about",
       defaults: new { controller = "mypagecontroller", action = "about" }
    );

    This works but when you have 50+ the code is quite lengthy.

    Is there a way I can reduce the length of each redirect or create a list (without using the database)?

    Thank you

    Wednesday, April 8, 2020 3:56 PM

All replies

  • User475983607 posted

    You are sharing a route not a redirect.

    Wednesday, April 8, 2020 4:10 PM
  • User-474980206 posted

    if you just want to rename the controller its:

    routes.MapRoute(
       name: "route_redirect_pages",
       url: "/pages/{action}",
       defaults: new { controller = "mypagecontroller", action = "about" }
    );

    or rename mypagecontroller to pagescontroller and use default routes.

    you could also switch to attribute routing 

      https://devblogs.microsoft.com/aspnet/attribute-routing-in-asp-net-mvc-5/

    Wednesday, April 8, 2020 6:30 PM