views:

61

answers:

3

Hey, I created a HttpHandler for downloading files from the server. It seems it is not handling anything...I put a breakpoint in the ProcessRequest, it never goes there.

public class DownloadHandler : IHttpHandler
{
   public void ProcessRequest(HttpContext context)
   {
        //download stuff and break point
   }
}

It never stops there, as mentioned. I also registered it in the web.config.

<add verb="*" path="????" type="DownloadHandler" />

I am not sure about the path part of that entry. What do I have to enter there? I am downloading txt files, but the URL does not contain the filename, I somehow have to pass it to the handler. How would I do this? Session maybe?

Thanks

+1  A: 

Have you seen this? Are you using IIS 6 or 7?

The path part should contain a (partial) url, so if in your case you are using a static url without the filenames, you should put that there. Yo can end the url in the name of a non-existent resource and map that to path

e.g. the url is http://myserver.com/pages/downloadfiles
and the path="downloadfiles"

If you do POST, you can put the filename in a hidden field, and extract it in the handler. If you're using GET, I'm not sure, either cross-post the viewstate or put the filename in the session like you said.

Any reason why you can't put the filename in the url?

StephaneT
bump for the first link, explains everything
annakata
A: 

Look at the answer I just posted here on Stack Overflow

TheGeekYouNeed
A: 

The path for a handler needs to be the path you are trying to handle - bit of a tautology I know but it's as simple as that. Whatever path on your site (real or much more likely virtual) you want to be handled by this handler.

Now unless the kind of file at the end of that path is normally handled by ASP.NET (e.g. .aspx, .asmx but not a .txt) ASP will never see the request in order for it to go through it's pipeline and end up at your handler. In that case you have to bind the extension type in IIS to ASP.NET.

As far as identifying what file the handler is supposed to respond with you could achieve this any number of ways - I would strongly recommend avoiding session or cookies or anything temporal and implicit. I would instead suggest using the querystring or form values, basically anything which will show up as a request header.

Fianlly, I have to ask why you're using a handler for this at all - .txt will serve just fine normally so what additional feature are you trying to implement here? There might well be a better way.

annakata