Mapping specific folder to HttpHandler in web.config

Is it possible to map all file extensions in a folder to a specific HttpHandler (assuming that their file extensions are mapped to aspnet_isapi.dll in IIS) ?

I’ve got the FLV extension mapped to ASP.NET in IIS, and have a folder named Static in my web application with the following files:

  • Static/Index.htm
  • Static/MyFile.flv

The index file is a basic html page using the JW FLV Media Player to play the FLV.

In Web.Config, under the HttpHanders section, the following works (FLV is loaded and plays successfully):

<add verb="*" path="MyFile.flv" type="MyApp.PassthroughFileHandler, MyApp"/>

But this doesn’t (video cannot be loaded):

<add verb="*" path="Static/*" type="MyApp.PassthroughFileHandler, MyApp"/>

I’ve tried various combinations, without much luck.

Ideally, I’d like to be able to have all FLV’s in the Static folder use the PassthroughFileHandler, rather than have to specify each filename individually in web.config.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Here is a diffrent way that doesn’t require a “dummy” folder and and a new web.config.

Add this to your main web.config

<location path="static">
  <system.web>
    <httpHandlers>
      <add verb="GET,HEAD" path="*.*" 
           type="MyApp.PassthroughFileHandler, MyApp" />
    </httpHandlers>
  </system.web>    
</location>

Method 2

Try placing a second web.config inside that folder, with something like:

<?xml version="1.0"?>
<configuration>
    <system.web>
      <httpHandlers>
        <!-- <clear/> -->
        <add verb="*" path="*.flv"
            type="WebApplication3.MyHandler, WebApplication3"/>
      </httpHandlers>
    </system.web>
</configuration>

Method 3

I think you need to go into IIS (I assume you’re using II 6) and configure ASP.NET to handle wildcard extensions. Because although you’ve mapped the .flv extension, IIS will handle Static/Index.htm normally and not pass it to ASP.NET.

http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx

You can probably configure IIS for just this static folder, though I’ve never tried this.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x