Routing a url with extension in MVC4 won't work, tries to serve up static file

倖福魔咒の 提交于 2019-11-28 10:57:16

You can add this to your web.config in the <system.webServer><handlers> section:

<add name="ManagedDllExtension" 
     path="data/fileinfo.xml" 
     verb="GET" type="System.Web.Handlers.TransferRequestHandler"
     preCondition="integratedMode,runtimeVersionv4.0" />

Your route would be

routes.MapRoute(
        name: "Data",
        url: "Data/fileinfo.xml",
        defaults: new { controller = "Data", action = "fileinfo"}
    );

There is also <modules runAllManagedModulesForAllRequests="true"> but it doesn't seem to work for MVC4/IIS8 (used to be ok in MVC3/IIS7 IIRC). More info here. There is also a performance impact with this one as every request will route through the managed pipeline.

HTH

I had the same issue with ASP MVC 4. In web.config syste.webserver.handlers section I found the next code:

<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />

All request that have .ext will be handled automatically by IIS. Those were missing in MVC 3.

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