Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of adding "routes.MapMvcAttributeRoutes()" to RegisterRoutes()?

According to the article "What's New in ASP.NET MVC5", you must add this to your RegisterRoutes() method in order to use Attribute Routing:

routes.MapMvcAttributeRoutes();

...so that the method is now:

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

    routes.MapMvcAttributeRoutes();

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

I do not have that additional/middle call, and my attribute routing has been working just dandy.

So what does adding that do for me, if anything?

like image 763
B. Clay Shannon-B. Crow Raven Avatar asked Feb 03 '14 16:02

B. Clay Shannon-B. Crow Raven


1 Answers

You only need this if you use attribute routing on your MVC controllers. Your WebAPI attribute routing works because of this line in WebApi.Config.cs

// Web API routes
config.MapHttpAttributeRoutes();
like image 179
Anthony Chu Avatar answered Sep 21 '22 19:09

Anthony Chu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!