我做了一些环顾四周,并没有偶然发现任何类似我正在经历的问题,所以我想我会把它扔到这里看看有什么特别的东西。
我有一个控制器和方法设置。
public class BoothAPIController : ITApiControllerBase
{
[HttpGet]
public HttpResponseMessage GetActiveAssetNumbersLike([FromUri] String id)
{
HttpResponseMessage ret;
// ... do some processing
return ret;
}
}
路线在Global.asax
中设置protected void Application_Start(object sender, EventArgs e)
{
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "CustomApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BoothWithDateAPI",
routeTemplate: "api/{controller}/{boothID}/{year}/{month}/{day}");
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
}
这两个请求执行完美......
http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PR
http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PRN0
但是这个......返回404错误......
http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PRN
失败请求的标头看起来像......
Cache-Control →private
Content-Length →2879
Content-Type →text/html; charset=utf-8
Date →Mon, 29 Aug 2016 12:53:08 GMT
Server →Microsoft-IIS/8.0
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
X-SourceFiles →= [string]
虽然成功的请求看起来像
Cache-Control →no-cache
Content-Length →7731
Content-Type →application/json; charset=utf-8
Date →Mon, 29 Aug 2016 13:13:43 GMT
Expires →-1
Pragma →no-cache
Server →Microsoft-IIS/8.0
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
X-SourceFiles → [string]
(Shrugs)我不知道......我完全失去了为什么参数中的一个变化会产生影响。
答案 0 :(得分:2)
我对此进行了一些挖掘,并对此感到惊讶。事实证明,您尝试发送的参数PRN
是MS-DOS Device Driver
以下是默认设备驱动程序名称列表。
PRN系统列表设备,通常是并行端口
这个问题有一个问题的答案: IIS gives 404 when MS-DOS reserved names are used in parameters values
但是你应该意识到将RelaxedUrlToFileSystemMapping
设置为真的潜在缺陷。请参阅Scott Hanselman的这篇文章:Experiments in Wackiness: Allowing percents, angle-brackets, and other naughty things in the ASP.NET/IIS Request URL