URL 段中的句点导致 404 错误

Period in URL segment causes 404 error

我有一条自定义路线:

<Route("maintenance/test/{one}/{two}/{three}")>
Function Test(ByVal one As String, ByVal two As String, ByVal three As String) As JsonResult
    Return Json(True, JsonRequestBehavior.AllowGet)
End Function

当我到达路线时,它按预期工作:

localhost:1337/maintenance/test/1/2/3

但是,如果任何参数中包含句点,例如:

localhost:1337/maintenance/test/1/2./3 (note period after 2)

我收到 404 "The resource cannot be found" 错误。

IIS 似乎正在获取 URL 并尝试提供静态文件而不是将其传递到 MVC。

我尝试过的事情(无济于事):

    <add name="ApiURIs-ISAPI-Integrated-4.0" 
         path="/people/*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" 
         type="System.Web.Handlers.TransferRequestHandler"
         preCondition="integratedMode,runtimeVersionv4.0" />

我最初认为 IIS 将请求视为资源请求的假设是不正确的。

事实证明,ASP.NET 阻止任何对 URL 和 ./ 的请求,其方式与阻止遗留保留字的方式相同。

解决方案是启用relaxedUrlToFileSystemMapping:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

来源: