Go to WebApi.Core error - direct route cannot use 'controller' parameter

I was forced to update Microsoft.AspNet.WebApi.Client and Microsoft.AspNet.WebApi.Core from version 5.0.0.0 to 5.2.0.0 due to a dependency on another project, and now my API throws an error "A direct route cannot use the parameter "controller." Specify a literal path instead of this parameter to create a route to the controller. "

The error is caused when HttpConfiguration is initialized in Global.asax.cs when called

GlobalConfiguration.Configure(WebApiConfig.Register); 

It seems that the main library is causing the problem. When I updated only the client, it did not give an error.

I noticed that if I comment on the attributes of the route from all the controllers within the project, then it no longer throws an error, for example.

 [Route("api/storage/series/{series}/documentId/{documentId}")] 

However, deleting this data is not a viable solution due to the number of dependent applications.

In Google / Binging the error there is almost zero useful information about this. Can anyone tell me about this error and suggest how I can fix it?

+8
c # asp.net-web-api asp.net-mvc-routing
source share
1 answer

Thought about it, or rather, my colleague. Now it seems obvious if you look at the error. This is due to route attributes on some of our controllers (just not in the example that I used in the question) containing {controller}. eg.

 [Route("api/{controller}/editGroups")] 

Changing this setting to use the name of the hard controller as shown below resolves the issue.

 [Route("api/documents/editGroups")] 
+16
source share

All Articles