0

I have `

public static void RegisterRoutes(RouteCollection routes)
{
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.LowercaseUrls = true;

        //routes.Add(new SubdomainRoute());

        routes.MapRoute("Default", "{controller}/{action}", new
        {
            controller = "Home",
            action = "Index"
        });

        routes.MapMvcAttributeRoutes();
    }

I which governs a lot of routes that the default template of mvc depends on (menu, account, registration etc)

I want to try to change /home/contact to simply /contact, so I did the logical thing by defining (HomeController)

    [Route("about", Name = "About")]
    public ActionResult About()
    {...}

This does not fire, however if i comment out the first part of the code, then this code is called.

Zoinky
  • 4,083
  • 11
  • 40
  • 78

1 Answers1

3

The order of routes registration is important. You need to call

routes.MapMvcAttributeRoutes();

prior to

routes.MapRoute("Default", "{controller}/{action}", new
        {
            controller = "Home",
            action = "Index"
        });
Alex Art.
  • 8,711
  • 3
  • 29
  • 47
  • Thank you, thank you, thank you! Missed that entirely - I've only ever used attribute routing in web api projects where the equivalent code is automatically inserted in WebApiConfig.cs. – K. Meke Nov 09 '17 at 19:31