HttpHandlers的与ASP.NET MVC [英] HttpHandlers with ASP.NET MVC

查看:81
本文介绍了HttpHandlers的与ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个标准AXD的HttpHandler,默认忽略*个.axd路线,那么为什么ASP.NET MVC仍然在处理请求的子目录,例如,如果有一个 /内容/ CSS提出的请求/ css.axd?d ....
如果请求在根/css.axd?d取得....一切工作正常。

If I have a standard AXD HttpHandler and the default ignore route for *.axd, then why is ASP.NET MVC still handling requests in subdirs, for instance if there is a request made for /Content/Css/css.axd?d.... If the request is made at root /css.axd?d.... everything works fine.

推荐答案

我猜的路线是故意做出这样的设计,也许是因为在字符串的开始通配符并不像高性能的。

I guess the route was deliberately made like that by design, maybe because the wildcard at a start of string isn't as performant.

可惜,这是行不通的:

routes.IgnoreRoute({*} pathAndResource个.axd / {*} PATHINFO)

routes.IgnoreRoute("{ *pathAndResource }.axd/{ *pathInfo }")

该解决方案是使用限制 - 见<一href=\"http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx\">Phil哈克的博客文章

The solution is to use constraints - see Phil Haack's blog post

菲尔的博客使用正前pression约束,但你可以创建自己的自定义的约束实现或者使事情变得更加可读:

Phil's blogs uses a regular expression constraint, but you could create you own custom contraint alternatively to make things more readable:

routes.IgnoreRoute("match axds"
 "{*url}", new { controller = "MyController", action = "MyAction" }, new
              {
                  myCustomConstraint = new FileExtensionConstraint(".axd")
              }

这篇关于HttpHandlers的与ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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