MVC Attribute Routing Not Working

Not only do you have to have the call to routes.MapMvcAttributeRoutes() in your App_Start\RouteConfig.cs file, it must appear before defining your default route! I add it before that and after ignoring {resource}.axd{*pathInfo}. Just found that out trying to get attribute routing to work correctly with my MVC 5 website.

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

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
        );

    }

Leave a Comment