我一直在使用Google和他的动手了几个小时,还没有真正取得了很大的进步,所以希望这里有人可以提供帮助。
I've been googling and tinkering for a couple hours and haven't really made much progress, so hopefully someone here can help.
我试图让所有的请求到一定的路径,通过第三方组件来处理。
I'm trying to get all requests to a certain path to be handled by a 3rd party component.
修改我需要所有的请求所有其他路径正常行为。
EDIT And I need all requests to all other paths to behave normally.
我使用的路由处理带有通配符映射是这样的:
I'm using a route handler with a wildcard mapping like this:
routes.Add(new Route("pathiwant/{*EverythingElse}", new MyRouteHandler()));
所有的传统路线前进正确的处理程序,它很好地转发给第三方组件。当我打的静态文件(html的,txt文件,等等),他们得到回升,由StaticFile处理程序,而不是我的处理程序,所以我试图关闭StaticFile处理像这样(简体):
All traditional routes forward correctly to the handler, which forwards nicely to the 3rd party component. When I hit static files (.html, .txt, etc.), they get picked up by the StaticFile handler instead of my handler, so I'm attempting to turn off the StaticFile handler like so (simplified):
<system.webServer>
<handlers>
<remove name="StaticFile"/>
</handlers>
</system.webServer>
这将关闭StaticFile处理程序,但MVC仍没有回暖的路由。
This turns off the StaticFile handler, but MVC still doesn't pick up the route.
我preFER不依傍创造我自己的处理程序,并注入了ASP请求堆栈,因为它似乎应该有一个MVC快乐的方式来做到这一点。
I'd prefer not to fall back on creating my own handler and injecting into the ASP request stack since it seems like there should be an MVC-happy way to do this.
有什么想法?和感谢。
这里有几个选项。
http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx
如果你真的想通过asp.net管道运行的所有请求,那么你需要的。
If you really want all requests running through the asp.net pipe then you need.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
更新
另一种选择,尤其是当需要绕过静态处理程序被限制到您的站点的子集,是使用以下
Another option, especially if your need to bypass the static handler is constrained to a subset of your site, is to use the following
<add name="ApiURIs-ISAPI-Integrated-4.0"
path="/subdirectory/*"
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
考虑如何MVC的网站,大多数静态文件是从几个知名的目录来处理,这是一个更好的选择。
Considering how on mvc sites, most static files are handled from a couple well known directories, this is a better option.