MVC路由静态文件

时间:2013-01-02 17:58:57

标签: c# asp.net-mvc asp.net-mvc-3 maproute

我正在使用传统的swf文件,该文件在控制器/操作路由中查找静态路由。例如,它正在尝试下载文件

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

当文件存在于根目录中时:

http://localhost:59801/ClearExternalPlaySeekMute.swf

我可以使用MapRoute将此网址映射到根目录吗?

2 个答案:

答案 0 :(得分:2)

您可以在IIS中使用url rewrite模块。安装后,只需添加以下重写规则:

<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>

现在,当向/Resource/Details/ClearExternalPlaySeekMute.swf发出请求时,/ClearExternalPlaySeekMute.swf将提供该请求。

答案 1 :(得分:1)

这应该对你有用,但我认为通过IIS会更好。

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

我记得一篇非常好的SO帖子。如果我找到它,我一定会参考。

基本上是同一个问题...... Using ASP.NET routing to serve static files