A route named "DefaultRoute" is already in the route collection. Route names must be unique.

When I publish a solution ASP.NET WebAPIfor remote IIS Server, I get an error message:

Message: System.ArgumentException: A route named "DefaultRoute" is already in the route collection. Route names must be unique.

I saw this thread with the same problem, but none of this worked. I tried:

  • Delete all bin / obj files in all projects.
  • Cleaning / Restoring
  • Removing files from a remote server before publishing
  • Rename a project

In any case, I can find out if there is an obsolete file. I renamed some files and I heard that this could cause a problem?

Not sure if that matters, but I'm using ASP.NET WebApi along with RestSharp to make my other calls.

This is what mine has Global.asax startup: is it redundant?

AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteConfig.RegisterRoutes(RouteTable.Routes);
+4
source share
6 answers

I ran into a similar problem with already established routes. For me, the decision was here: fooobar.com/questions/277950 / ... . The problem was that I later renamed the project file - old DLL files with the previous name still existed in the / bin directory, and automatic startup setup also starts them.

+8
source

. global.asax, RouteConfig.cs( /App _Start {isaname} AreaRegistration.cs, /Areas/ {isaname}. . , "DefaultRoute" , , , . , .

+1

, , RouteAttribute, , , HTTP GET HTTP POST:

[HttpGet]
[Route("MyApiMethod", Name = "MyApiMethod")]
public MyApiMethod PropertyData(...)
{
    ...
}

// ERROR: Causes "System.ArgumentException: A route named 'DefaultRoute' is already in the route collection. Route names must be unique."
[HttpPost]
[Route("MyApiMethod", Name = "MyApiMethod")]
public MyApiMethod PropertyData(...)
{
    ...
}

, , : Name. Name, ( ), :

[HttpGet]
[Route("MyApiMethod", Name = "MyApiMethod-GET")]
public MyApiMethod PropertyData(...)
{
    ...
}

[HttpPost]
[Route("MyApiMethod", Name = "MyApiMethod-POST")]
public MyApiMethod PropertyData(...)
{
    ...
}
+1
  • Global.asax

.

AreaRegistration.RegisterAllAreas();

  1. .
0

. IIS 8.X, .

  • "Running" .
  • PreLoad Enabled "" .

, .

0

SOlution !

0

All Articles