MVC routing static file

2019-04-29 18:47发布

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?

2条回答
一纸荒年 Trace。
2楼-- · 2019-04-29 19:10

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-04-29 19:26

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

查看更多
登录 后发表回答