You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
// Setup API Versioning
config.AddApiVersioning(o =>
{
// commenting this out still produces the /v1 403 error
o.DefaultApiVersion = new ApiVersion(2,0);
});
config.Routes.MapHttpRoute(
name: "DefaultApi-Versioned",
routeTemplate: "v{apiversion}",
defaults: new { controller = "Echo" },
constraints: new { apiVersion = new ApiVersionRouteConstraint() }
);
}
}
EchoController.cs:
[ApiVersion("1")]
public class EchoController : ApiController
{
public Agreement Get()
{
return new Agreement(GetType().FullName, "version-1", Request.GetRequestedApiVersion().ToString());
}
}
public class Agreement
{
public Agreement(string controller, string accountId, string apiVersion)
{
Controller = controller;
AccountId = accountId;
ApiVersion = apiVersion;
}
public string Controller { get; set; }
public string AccountId { get; set; }
public string ApiVersion { get; set; }
}
}
namespace WebApiVersioningV1Test.V2.Controllers
{
using WebApiVersioningV1Test.V1.Controllers;
[ApiVersion("2")]
public class EchoController : ApiController
{
public Agreement Get()
{
return new Agreement(GetType().FullName, "version-2", Request.GetRequestedApiVersion().ToString());
}
}
#73 was more about providing a default value for the API version in the middle of the template. That isn't something supported by the platform I'm afraid. You'd have to create multiple routes declaratively with attributes or imperatively at runtime (as described in #73). I actually did investigate using default values in the template like /v{version:apiVersion=42}, but it doesn't work. :(
I'm not sure that's necessarily your issue. I find it odd that /v2 works, but /v1 does not. They should either both work or both fail. Can you share your repro? You can just zip it up and attach it to this thread. Thanks.
When prepping the files, I made a small change and the problem disappeared:
If I move the Controllers folder out of the subfolder /V1, and into the root of the site.
And, I delete the /V1 folder ...
Then the problem doesn't occur. It only occurs if the /V1 folder exists.
Ohhhhh ... I remember reading that the default behavior of Web API routing is something like "if a file or folder actually exists on disk, then Web API routing will not process the request." So, the 403 Forbidden is because the permissions to list a folders contents are denied.
Thanks for being there and letting me bounce the issue off you; I think I'll mark this as closed.
Hello,
This is a very specific use case:
ApiVersionRouteConstraint
With this setup:
And, it's only the /v1 route. If you change the
DefaultApiVersion
or other configuration options, the problem continues to occur only on /v1.To reproduce the issue, I used:
Install-Package Microsoft.AspNet.WebApi.Versioning
WebApiConfig.cs
\Controllers\EchoController.cs
WebApiConfig.cs
:EchoController.cs
:I've read through the Known Limitations with Url Path Segment Routing, and I've read through Issue 73 (BTW- The link on the wiki page needs to be updated). But, it doesn't seem to describe my exact issue.
Do you have any thoughts on what might be going on?
Thanks In Advance
The text was updated successfully, but these errors were encountered: