Description
Hi,
I implemented this package in api and after that I am getting this error:
No route providing a controller name with API version '2' was found to match request URI 'http://localhost:52477/api/V2/path'
Please note that, code is working if I use 'http://localhost:52477/api/path?api-version=1.0' or 'http://localhost:52477/api/path?api-version=2.0'.
WebApiConfig code:
// added to the web api configuration in the application setup
var constraintResolver = new DefaultInlineConstraintResolver()
{
ConstraintMap =
{
["apiVersion"] = typeof( ApiVersionRouteConstraint )
}
};
config.MapHttpAttributeRoutes(constraintResolver);
// allow a client to call you without specifying an api version
// since we haven't configured it otherwise, the assumed api version will be 1.0
config.AddApiVersioning(o => o.AssumeDefaultVersionWhenUnspecified = true);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I am using RoutePrefix to add version to the route:
[ApiVersion("1.0")]
[RoutePrefix("api/v{version:apiVersion}/Home")]
public class HomeController : ApiController
{
--code here--
}
[ApiVersion("2.0")]
[RoutePrefix("api/v{version:apiVersion}/Home")]
public class HomeControllerV2 : ApiController
{
--code here--
}
Please do help. I am stuck here.