[英]Attribute Route with constraint works locally but fails when deployed
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. 虽然在本地开发时路由有效,但是当我将其部署到IIS服务器时路由失败(404)。
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): 我确定这不是IIS问题,因为我仍然可以使用非属性路由来访问服务(请注意,即使
v1
不是int,参数本身也具有默认值):
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. 我已经安装了Route Debugging,并且正如预期的那样,即使应该,我的路由也不匹配属性route。
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). 应用程序相对路径列为
~/v1/search/products
,应与网址格式v{version}/{category}/{service}
匹配(“ version”也正确列出并带有int路由约束)。
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
. 感谢@Kiran Challa,我意识到,尽管类似,但是内置的WebAPI属性路由与
AttributeRouting.WebApi
并不相同。 I switched to the built-in routing and it all works fine now. 我切换到内置路由,现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.