Home > DeveloperSection > Forums > A route named 'DefaultApi' is already in the route collection
Pravesh Singh

Total Post:412

Posted on    December-02-2014 10:25 PM

 ASP.NET MVC ASP.Net  Mvc  Url Routing 

 1 Reply(s)
 3329  View(s)
Rate this:

This question may seems duplicate but this is slightly different. In all other question in SO I had noticed that they have multiple routes registered. but in my case I have just one route.


I am creating asp.net webapi (framework 4.5) and have just one route in RegisterRoutes() method -


    public static void RegisterRoutes(RouteCollection routes)





            name: "DefaultApi",

            url: "rest/{controller}/{id}",

            defaults: new { id = UrlParameter.Optional }




Then why is it throwing error?


A route named 'DefaultApi' is already in the route collection. Route names must be unique. Parameter name: name

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    December-03-2014 6:52 AM

Instead of adding it in the route collection, added it in HttpConfiguration


            name: "DefaultApi",

            routeTemplate: "rest/{controller}/{id}",

            defaults: new { id = RouteParameter.Optional }


Don't want to miss updates? Please click the below button!

Follow MindStick