MVC routing static file

99封情书 提交于 2019-12-22 07:47:24

问题


I am working with a legacy swf file that is looking in the controller/action routing for a static route. For example, it is trying to download the file

http://localhost:59801/Resource/Details/ClearExternalPlaySeekMute.swf

When the file exists in the root directory:

http://localhost:59801/ClearExternalPlaySeekMute.swf

Can I use MapRoute to map this URL to the root directory?


回答1:


You could use the url rewrite module in IIS. Once you install it simply add the following rewrite rule:

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite Static Flash file" stopProcessing="true">
          <match url="^Resource/Details/ClearExternalPlaySeekMute.swf$" />
          <action type="Rewrite" url="ClearExternalPlaySeekMute.swf" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

Now when a request is made to /Resource/Details/ClearExternalPlaySeekMute.swf it will be served by /ClearExternalPlaySeekMute.swf.




回答2:


This should work for you, but I think this would be better through IIS.

routes.IgnoreRoute("{file}.swf");

I remember a SO post that was really good. If I find it, I'll be sure to reference.

Basically the same question... Using ASP.NET routing to serve static files



来源:https://stackoverflow.com/questions/14126842/mvc-routing-static-file

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