asp.net-mvc 为什么我可以从 MVC 应用程序中删除 ExtensionlessUrlHandler 而没有任何不良影响?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26271958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can I remove ExtensionlessUrlHandler from an MVC application without any ill effects?
提问by Giorgio
I am trying to streamline my MVC application and deleting as much as possible. Can someone explain to me what this code below does in the web.config file in the root of the application. I have commented it out and still managed to run the application...
我正在尝试简化我的 MVC 应用程序并尽可能多地删除。有人可以向我解释以下代码在应用程序根目录的 web.config 文件中的作用。我已将其注释掉,但仍然设法运行该应用程序...
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
...
I have looked at this question: ASP.NET MVC 4 and ExtensionlessUrlHandlerwhich has an answer that links to this blog: http://blogs.msdn.com/b/tmarq/archive/2010/05/26/how-extensionless-urls-are-handled-by-asp-net-v4.aspxbut I don't find it to explain my question.
我看过这个问题:ASP.NET MVC 4 and ExtensionlessUrlHandler有一个链接到这个博客的答案:http: //blogs.msdn.com/b/tmarq/archive/2010/05/26/how-extensionless- urls-are-handled-by-asp-net-v4.aspx但我找不到它来解释我的问题。
I am using: IIS 8, ASP.NET MVC 4, .NET 4.5 in both development and production
我在开发和生产中使用:IIS 8、ASP.NET MVC 4、.NET 4.5
采纳答案by Ori Calvo
IIS express uses different handlers names than IIS
IIS express 使用与 IIS 不同的处理程序名称
Add the following markup and it should disable the extensionless handlers for IIS express only
添加下面的标记和IIS的表达应该禁用扩展名的处理程序只
<remove name="ExtensionlessUrl-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrl-Integrated-4.0" />
回答by Ori Calvo
You should check your web.config file. If the following setting is present
您应该检查您的 web.config 文件。如果存在以下设置
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
Then, it could explain why everything is still working after deleting the ExtensionlessUrlHandler handlers.
然后,它可以解释为什么在删除 ExtensionlessUrlHandler 处理程序后一切仍然有效。
By default the runAllManagedModulesForAllRequestsis false which means that IIS does not delegate each request to managed (.NET) modules. The core module which knows how to handle extension less URL is named UrlRouting module and it is a managed (not native) module. This means that it doesn't have a chance to handle the request and IIS internally tries to handle it according to its handler mapping configuration. BTW, the default configuration treat the extensionless url as a static resource and therefore fails with 403.14 status code (in most cases)
默认情况下,runAllManagedModulesForAllRequests为 false,这意味着 IIS 不会将每个请求委托给托管 (.NET) 模块。知道如何处理无扩展 URL 的核心模块称为 UrlRouting 模块,它是一个托管(非本机)模块。这意味着它没有机会处理请求并且 IIS 在内部尝试根据其处理程序映射配置来处理它。顺便说一句,默认配置将无扩展名 url 视为静态资源,因此失败并显示 403.14 状态代码(在大多数情况下)
When runAllManagedModulesForAllRequestsis true any request being sent to IIS is directed to any managed module. The UrlRouting module has a change to process the request and delegate it to ASP.NET MVC.
当runAllManagedModulesForAllRequests为 true 时,发送到 IIS 的任何请求都将定向到任何托管模块。UrlRouting 模块进行了更改以处理请求并将其委托给 ASP.NET MVC。
To summarize, when running ASP.NET MVC applications you have two options
总而言之,在运行 ASP.NET MVC 应用程序时,您有两个选择
- runAllManagedModulesForAllRequests is false. The ExtensionlessUrlHandler must be registered
- runAllManagedModulesForAllRequests is true. You can delete ExtensionlessUrlHandler from the IIS handlers list
- runAllManagedModulesForAllRequests 为假。必须注册 ExtensionlessUrlHandler
- runAllManagedModulesForAllRequests 为真。您可以从 IIS 处理程序列表中删除 ExtensionlessUrlHandler

