简体   繁体   English

具有约束的属性路由在本地工作,但在部署时会失败

[英]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.

相关问题 将映像上传到Azure Blob存储-本地工作,部署后失败 - Uplod images to azure blob storage - Works locally, fails when deployed Database First DBContext在本地工作,但在部署时无法工作 - Database First DBContext works locally but not when deployed JavaScript在本地运行,但在部署到Web服务器时无法运行 - JavaScript works locally but not when deployed to webserver 简单的WebClient在本地工作,但在部署到Azure时无法工作 - Simple WebClient works locally, but not when deployed to Azure WebApi在本地工作,但在发布时失败 - WebApi works locally but when published It fails 代理在本地工作,但在上传到webhost时失败 - Proxy works locally but fails when uploaded to webhost 我的asmx Web服务在本地工作,但在远程IIS 7上部署时不工作 - My asmx webservice works locally but not when deployed on remote IIS 7 ASP.NET Core(HttpSys)路由在本地工作,但在部署时不工作 - ASP.NET Core (HttpSys) Routing works locally but not when deployed pyinstaller .exe在本地工作,但是在被C#调用时失败? - pyinstaller .exe works locally but fails when called by C#? ASP.Net 页面在本地工作但在推送到服务器时失败 - ASP.Net Page Works Locally But Fails When Pushed To Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM