Reputation: 1642
I want to do a routing for an API, that is versioned.
The Folder structure is like this
/api/v1-0/ApiController.cs
/api/v1-1/ApiController.cs
/api/v1-2/ApiController.cs
So I added the route
routes.MapRoute(
name: "DefaultApiVersioned",
url: "api/v{*Version}/{controller}/{action}/{id}",
defaults: new { controller = "Api", action = "Index", id = UrlParameter.Optional }
);
But when the route is added, I get an "ArgumentException
". The exception message is:
"Ein Pfadsegment, das mehrere Abschnitte enthält, z.B. einen Literalabschnitt oder einen Parameter, darf keinen Catchall-Parameter enthalten. "
Translation:
"A path segment, that has multiple sections, such as a literal section or a parameter, can not have a catchall parameter"
So how do I have to change my route config?
Upvotes: 1
Views: 4638
Reputation: 1038930
You don't need a wildcard:
routes.MapRoute(
name: "DefaultApiVersioned",
url: "api/v{version}/{controller}/{action}/{id}",
defaults: new { controller = "Api", action = "Index", id = UrlParameter.Optional }
);
The wildcard can only be used as last segment of a route definition.
Upvotes: 8