I have a simple attribute route with three different path segments:
[HttpGet]
[GET("v{version:int}/{category}/{service}")]
public async Task<HttpResponseMessage> RouteMessage(
string category, string service, int version = 1)
{
}
While the routing works when developing locally, it fails (404) when I deploy it to an IIS server.
The URL that fails:
http://example.com/v1/search/products?client=test
I'm certain it's not an IIS issue because I can still access the service using non-attribute routing (note that even though v1
isn't an int, the parameter itself has a default value):
http://example.com/api/route/?version=v1&category=search&service=products&client=test
I've installed Route Debugging and, as expected, my route does not match the attribute route even though it should.
The app-relative path is listed as ~/v1/search/products
, which should match the url format v{version}/{category}/{service}
("version" is also correctly listed with an int route constraint).
Here's an image with the full debug info in case it helps.
Thanks to @Kiran Challa I realized that, although similar, the built-in WebAPI attribute routing is not the same as AttributeRouting.WebApi
. I switched to the built-in routing and it all works fine now.