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。
我尝试过的事情(无济于事):
- 添加尾部斜杠以强制 IIS 将其识别为 URL 而不是资源
- 根据 this answer.
将 runAllManagedModulesForAllRequests="true"
添加到 web.config 的 <system.webServer><modules>
- 根据[此答案]添加 TransferRequestHandler 处理程序:()
<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" />
- 正在将 MVC 5 更新到最新版本 (5.2.3)
我最初认为 IIS 将请求视为资源请求的假设是不正确的。
事实证明,ASP.NET 阻止任何对 URL 和 ./
的请求,其方式与阻止遗留保留字的方式相同。
解决方案是启用relaxedUrlToFileSystemMapping
:
<httpRuntime relaxedUrlToFileSystemMapping="true" />
来源:
- 被黑 - Allowing reserved filenames in URLs
- This answer SO(尽管评论说它不适用于 MVC 5)
我有一条自定义路线:
<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。
我尝试过的事情(无济于事):
- 添加尾部斜杠以强制 IIS 将其识别为 URL 而不是资源
- 根据 this answer. 将
- 根据[此答案]添加 TransferRequestHandler 处理程序:()
runAllManagedModulesForAllRequests="true"
添加到 web.config 的 <system.webServer><modules>
<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" />
- 正在将 MVC 5 更新到最新版本 (5.2.3)
我最初认为 IIS 将请求视为资源请求的假设是不正确的。
事实证明,ASP.NET 阻止任何对 URL 和 ./
的请求,其方式与阻止遗留保留字的方式相同。
解决方案是启用relaxedUrlToFileSystemMapping
:
<httpRuntime relaxedUrlToFileSystemMapping="true" />
来源:
- 被黑 - Allowing reserved filenames in URLs
- This answer SO(尽管评论说它不适用于 MVC 5)