MVC routing static file

2019-04-29 18:59发布

问题:

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