从截获的文件名状的URL prevent静态文件处理程序 [英] Prevent static file handler from intercepting filename-like URL

查看:112
本文介绍了从截获的文件名状的URL prevent静态文件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web应用程序我有一个看起来像这样的路线:

In my web application I have a route which looks like this:

routeCollection.MapRoute(
    "AdfsMetadata",                                                // name
    "FederationMetadata/2007-06/FederationMetadata.xml",           // url
    new { controller = "AdfsController", action = "MetaData" });   // defaults

这条路线背后的想法是与查找AD FS元数据,在这一点上微软AD FS服务器(2.0+)更好的工作时,你只是指定主机名。随着MVC3都能正常运作。但是,我们最近升级了项目MVC4现在的404呼叫此URL的结果,错误页面上提到的处理器是 StaticFile 和物理路径是 D:\\路径\\为\\我的\\项目\\ FederationMetadata \\ 2007-06 \\ FederationMetadata.xml 。我认为MVC或ASP.NET认为它必须是一个静态文件的请求,并查找该文件,但它不是一个文件。这些数据是动态生成的 - 这就是为什么我击溃了URL到控制器的动作。问题是,即使路线通过调试菲尔哈克不起作用。这只是与除没有进一步的信息404 IIS试图访问一个物理文件,该文件是不存在。

The idea behind this route was to work better with Microsoft AD FS server (2.0+) which looks for AD FS metadata at this point when you just specify a host name. With MVC3 all worked fine. But we upgraded the project to MVC4 recently and now the call for this URL results in a 404, the handler mentioned on the error page is StaticFile and the physical path is D:\path\to\my\project\FederationMetadata\2007-06\FederationMetadata.xml. I assume that MVC or ASP.NET "thinks" it must be a request for a static file and looks for the file, but it isn't a file. The data is generated dynamically - that's why I routed the URL to a controller action. The problem is that even the Route Debugger by Phil Haack doesn't work. It's just a 404 with no further information besides that IIS tried to access a physical file which isn't there.

有没有人有一个解决方案?我只是想这个URL路由到一个控制器动作。

Does anyone have a solution for this? I just want this URL to be routed to a controller action.

PS:我的不是100%的肯定的原因是升级到MVC4,这只是一个猜测,因为在大约同一时间升级发生错误,同样的路线工作中,依然采用MVC3另一个项目。

P.S.: I'm not 100% sure that the cause was the upgrade to MVC4, it was just a guess because the error occurred at about the same time as the upgrade, and the same route works in another project which is still using MVC3.

修改

我有一个自定义的的ControllerFactory 这需要完整的类名( AdfsController 而不是 ADFS ),所以后缀控制器是正确的在这种情况下。

I have a custom ControllerFactory which needs the full class name (AdfsController instead of Adfs), so the suffix Controller is correct in this case.

推荐答案

添加以下到<处理> &LT的部分; system.webServer> 节点:

<add 
    name="AdfsMetadata" 
    path="/FederationMetadata/2007-06/FederationMetadata.xml" 
    verb="GET" 
    type="System.Web.Handlers.TransferRequestHandler" 
    preCondition="integratedMode,runtimeVersionv4.0" />

这指示IIS GET请求到指定的URL应该由托管管道来处理,而不是作为静态文件和IIS服务直接。

This instructs IIS that GET requests to the specified url should be handled by the managed pipeline and not considered as static files and served by IIS directly.

我有需要完整的类名称自定义的ControllerFactory
  (AdfsController而不是ADFS),所以后缀控制器是正确的
  在这种情况下

I have a custom ControllerFactory which needs the full class name (AdfsController instead of Adfs), so the suffix Controller is correct in this case.

仔细检查这个请。尝试使用和不使用的路由定义的控制器后缀。

Double check this please. Try with and without the Controller suffix in the route definition.

这篇关于从截获的文件名状的URL prevent静态文件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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