I have a Web API 2 project hosted through an OWIN middleware. Everything worked perfectly fine and I am able to call my APIs as expected. But, my WebApiConfig defines the default route as follows:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Accordingly, I have to call my APIs using URLs similar to: /api/values/dosomething
This worked for me until I decided to document my API. For that, I first tried using the WebAPI Help Page package which did not work. Then I thought I should try Swashbuckle Swagger and see if that helps me avoid the problem altogether, but unfortunately, in both cases I got the same error:
The route template separator character '/' cannot appear consecutively. It must be separated by either a parameter or a literal value. Parameter name: routeTemplate
After trying a few things, it turned out that when change the route template and remove the {action}
part, the error is gone. But, I cannot really do that because the whole project assumes that URLs include the action method name in them.
So anyway, I would like to know the following:
- Why is this happening in the first place?
- Is there a way to modify this behavior?
Thanks in advance!