HttpHandlers with ASP.NET MVC

前端 未结 1 1822
北恋
北恋 2021-01-06 16:32

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 m

相关标签:
1条回答
  • 2021-01-06 16:44

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

    Unfortunately this won't work:

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

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

    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")
                  }
    
    0 讨论(0)
提交回复
热议问题