为什么 ASP.NET 路由优先于 web.config Http Handlers 部分?
我们的商店正在将 ASP.NET MVC 集成到一个大型 Web 应用程序中,该应用程序利用自定义和自定义功能。在 system.webServer\handlers 下的 web.config 中定义的第 3 方 HTTP 处理程序。以这种方式利用 HTTP 处理程序对我们来说非常有用,因为我们不需要重新编译应用程序,也不需要将实际的处理程序页面放在磁盘上产品每个实例的 Web 范围内的某个位置。
是否真的有必要在我们的 global.asax 中添加显式的忽略路由,以便运行时可以遵循 web.config 中定义的处理程序?我本以为 Web.Routing 会在检查了 system.webServer\handlers 中定义的处理程序之后调用(而不是相反)。
我们使用模块化设计,允许在添加功能时从 web.config 添加/删除处理程序。随着 MVC 路由的引入,我们似乎需要在 global.asax 文件中为 web.config 中定义的每个可能的处理程序添加忽略路由。
请注意,这些处理程序的实际文件并不存在于磁盘上 - 它们是虚拟的并嵌入在程序集中。下面是第 3 方处理程序的示例,现在需要在 global.asax 中显式忽略路由:
<system.webServer>
<handlers>
<!-- telerik radcontrols -->
<add name="TelerikDialogHandler" verb="*" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI, Version=2009.1.402.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"></add>
</handlers>
</system.webServer>
因此,如果您使用 System.Web.Routing,则必须包含在 Web.Config 中指定的 Http 处理程序的忽略路由?或者也许我做错了什么?
Our shop is integrating ASP.NET MVC into a large web application that utilizes custom & 3rd party HTTP Handlers defined in web.config under system.webServer\handlers. Leveraging HTTP Handlers in this way has been great for us because we don't need to recompile the app or have the actual handler page sitting on disk somewhere in the web scope for each instance of the product.
Is it really necessary to add explicit Ignore Routes in our global.asax so the Runtime can honor our Handlers defined in web.config? I would have thought Web.Routing would be invoked after the handlers defined in system.webServer\handlers have been checked (not the other way around).
We use a modular design that allows adding/dropping Handlers from web.config when features are added. With the introduction of MVC routing it appears we need to add ignore routes in the global.asax file for every possible handler defined in web.config.
Note the actual file to these Handlers don't exist on disk - they are virtual and embedded in an assembly. Here's an example of a 3rd party handler that now requires an explicit Ignore Route in global.asax:
<system.webServer>
<handlers>
<!-- telerik radcontrols -->
<add name="TelerikDialogHandler" verb="*" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI, Version=2009.1.402.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"></add>
</handlers>
</system.webServer>
So for the record if you use System.Web.Routing you must include Ignore Routes for Http Handlers specified in Web.Config? Or perhaps I'm doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ASP.NET 请求处理基于管道模型,其中 ASP.NET 将 http 请求传递到管道中的所有模块。每个模块接收http请求并对其具有完全控制权。一旦请求通过所有 HTTP 模块,它最终会由 HTTP 处理程序进行处理。 HTTP 处理程序对其执行一些处理,结果再次通过管道中的 HTTP 模块。
我认为考虑这些的最好方法是,HttpModule 是一个过滤器,当事件发生时,它会从请求对象中添加或减去某些内容,而 HttpHandler 是实际服务请求的处理器。 ASP.NET 请求生命周期的设置方式是:在进行处理之前,所有过滤器首先应用于请求。
ASP.NET request processing is based on a pipeline model in which ASP.NET passes http requests to all the modules in the pipeline. Each module receives the http request and has full control over it. Once the request passes through all of the HTTP modules, it is eventually processed by an HTTP handler. The HTTP handler performs some processing on it, and the result again passes through the HTTP modules in the pipeline.
I think that the best way to think about these is that HttpModule is a filter that adds or subtracts something from the request object when an event occurs and the HttpHandler is a processor that actually serves the request. The ASP.NET request lifecycle is setup in such a way that all filters are applied to the request first before processing occurs.