Prevent static file handler from intercepting filename-like URL

后端 未结 2 1809
醉话见心
醉话见心 2021-01-04 05:30

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

routeCollection.MapRoute(
    \"AdfsMetadata\",                    


        
相关标签:
2条回答
  • 2021-01-04 06:15

    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)

    0 讨论(0)
  • 2021-01-04 06:27

    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.

    0 讨论(0)
提交回复
热议问题