URL 中的点导致 404 与 ASP.NET mvc 和 IIS [英] Dots in URL causes 404 with ASP.NET mvc and IIS

查看:38
本文介绍了URL 中的点导致 404 与 ASP.NET mvc 和 IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目要求我的 URL 在路径中包含点.例如,我可能有一个 URL,如 www.example.com/people/michael.phelps

I have a project that requires my URLs have dots in the path. For example I may have a URL such as www.example.com/people/michael.phelps

带点的 URL 生成 404.我的路由很好.如果我传入 michaelphhelps,没有点,那么一切正常.如果我添加点,我会收到 404 错误.示例站点在带有 IIS8 Express 的 Windows 7 上运行.URLScan 未运行.

URLs with the dot generate a 404. My routing is fine. If I pass in michaelphelps, without the dot, then everything works. If I add the dot I get a 404 error. The sample site is running on Windows 7 with IIS8 Express. URLScan is not running.

我尝试将以下内容添加到我的 web.config:

I tried adding the following to my web.config:

<security>
  <requestFiltering allowDoubleEscaping="true"/>
</security>

不幸的是,这并没有什么不同.我刚刚收到一个 404.0 Not Found 错误.

Unfortunately that didn't make a difference. I just receive a 404.0 Not Found error.

这是一个 MVC4 项目,但我认为这无关紧要.我的路由工作正常,我期望的参数在那里,直到它们包含一个点.

This is a MVC4 project but I don't think that's relevant. My routing works fine and the parameters I expect are there, until they include a dot.

我需要配置什么才能在我的 URL 中包含点?

What do I need to configure so I can have dots in my URL?

推荐答案

我通过编辑我网站的 HTTP 处理程序使这个工作正常进行.对于我的需要,这很有效并解决了我的问题.

I got this working by editing my site's HTTP handlers. For my needs this works well and resolves my issue.

我只是添加了一个新的 HTTP 处理程序来查找特定的路径标准.如果请求匹配,它会正确发送到 .NET 进行处理.我对 URLRewrite hack 或启用 RAMMFAR 的解决方案更满意.

I simply added a new HTTP handler that looks for specific path criteria. If the request matches it is correctly sent to .NET for processing. I'm much happier with this solution that the URLRewrite hack or enabling RAMMFAR.

例如要让 .NET 处理 URL www.example.com/people/michael.phelps 将以下行添加到您站点的 web.config 中的 system.webServer/handlers 元素:

For example to have .NET process the URL www.example.com/people/michael.phelps add the following line to your site's web.config within the system.webServer / handlers element:

<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" />

编辑

还有其他帖子建议解决此问题的方法是 RAMMFARRunAllManagedModulesForAllRequests.启用此选项将为所有请求启用所有托管模块.这意味着静态文件(例如图像、PDF 和其他所有内容)将在不需要时由 .NET 处理.除非您有特定情况,否则最好不要使用此选项.

There are other posts suggesting that the solution to this issue is RAMMFAR or RunAllManagedModulesForAllRequests. Enabling this option will enable all managed modules for all requests. That means static files such as images, PDFs and everything else will be processed by .NET when they don't need to be. This options is best left off unless you have a specific case for it.

这篇关于URL 中的点导致 404 与 ASP.NET mvc 和 IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆