5

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user547794
  • 14,263
  • 36
  • 103
  • 152

2 Answers2

2

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I did consider this, but what about when I am debugging locally w/ IIS Express? – user547794 Jan 02 '13 at 18:24
  • Since IIS express is using the same IIS binaries (and most features of full iis) you can use url rewrite – Adam Tuliper Jan 02 '13 at 18:48
  • Url rewrite is built-in IIS Express - so there's absolutely nothing you need to do to make this work in IIS Express (other than putting the section I have showed you in your web.config). For IIS you have to install the Url Rewrite module. But that's as simple as enabling the feature in the server manager. – Darin Dimitrov Jan 02 '13 at 19:47
1

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

Community
  • 1
  • 1
MisterIsaak
  • 3,882
  • 6
  • 32
  • 55
  • Rather than just ignoring the file path, I actually need to re-direct that content to the root directory. The URL is hardcoded in the swf file. – user547794 Jan 02 '13 at 18:39
  • This answer is correct, but I think your bigger problem is you are using the catch all route definition that comes with ASP.NET MVC which you shouldn't. You should define your routes more specifically so that static files get served regardless and don't hit your routes. – Khalid Abuhakmeh Jan 08 '13 at 16:23