title: IHttpHandler that handles all URL extensions in IIS 6, IIS 7 and ASP.NET Development Server
body: <p>We have a custom IHttpHandler that is responsible for file downloads. The handler is mapped to URL /downloadfile.rem </p>
  
  <p>The browser redirects user to URL formatted like:<br>
  /downloadfile.rem/[fileID]/[mimeType]/[fileName].[extension]<br>
  example:<br>
  /downloadfile.rem/54923876129874545456621/text$plain/data.txt</p>
  
  <p>Our handler gets the supplied information from the URL and responses with file data.</p>
  
  <p>This method works in IIS 6 and IIS 7, but we have a problem with the ASP.NET Development Server. It seems, that IIS 6 and IIS 7 look at the URL from left to right and stop and the  "downloadfile.rem" part and correctly invoke our custom handler. The ASP.NET Development Server seems to look and the URL from right to left and decides what to do with the file based on the extension at the end of the URL. This gives a 404 reponse. When we remove the extension from the end of the URL, everything works as expected.</p>
  
  <p>This is our entry in httpHandlers section:  </p>
  
  <blockquote>
    <p>&lt;add verb="GET" path="downloadfile.rem" type="OurNamespace.DownloadFileHandler"/&gt;</p>
  </blockquote>
  
  <p>This is our entry in handlers section:</p>
  
  <blockquote>
    <p>&lt;add name="DownloadFile" verb="GET" path="downloadfile.rem" type="OurNamespace.DownloadFileHandler"/&gt;</p>
  </blockquote>
  
  <p><strong>How to make it work correctly in ASP.NET Development Server?</strong></p>
  
  <blockquote>
    <p>Rationale - why we do this the way we do it?<br>
    The files for download are generated dynamically as a result of an Ajax request. Since it is an Ajax request, we cannot return the file directly to the browser, but store it on the disk for the browser to request it later. The file name on the server side is the SHA-1 of the file contents (without extension).<br>
    We could simply make the browser send a GET request to a URL like<br>
    /downloadfile.rem?fileID=37452834576542345676234?mimeType=text$plain?fileName=data.csv<br>
    and on the server side return a Content-Disposition header with "attachment; filename=...", but there is a bug in a certain version of IE 6 (that we have to support), that ignores the filename part of the header and the user will be requested to save a downloadfile.rem file.<br>
    Therefore our URL must end with the filename that should be given to the file.</p>
  </blockquote>