Prevent static file handler from intercepting filename-like URL

只愿长相守 提交于 2019-12-01 03:26:13

Add the following to the <handlers> section of the <system.webServer> node:

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

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.

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.

IIS by default is serving that file as static withouth going into ASP pipeline, can you change the route to not have a .xml extension (which is not necessary at least you have a specific requirement about that)

You can specifiy the route like this:

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

Other solution would be to add to your web.config

<modules runAllManagedModulesForAllRequests="true">

but I recommend you to avoid this as possible since what it does is to stop IIS from serving all static files

EDIT Last try... a custom http handler for that specific path would work. This post is similar to your problem only that with images (look for "Better: Custom HttpHandlers" section)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!