IHttphandler for checking downloadable files such as .zip RRS feed

  • Question

  • User309311432 posted

    hi everyone

    I have a problem with Ihttphandler.

    I want to create an Ihttphandler that controls user whether the user is one of the members of my web site when the user request a downloadble files such as .zip or .rar. I have written and given it below my codes dont work. When files are requested, Ihttphandler checks user but it doesnt let the user download the file. Anyone solve the problem please?

    public class handler : IHttpHandler


       public bool IsReusable


          get { return false; }


    public void ProcessRequest(HttpContext context)


          string[] parts = context.Request.Url.Segments;

          string last = parts[parts.Length - 1];

          if (context.User.Identity.IsAuthenticated)


             context.Response.WriteFile("files/" + last);








    Sunday, March 19, 2006 4:02 PM

All replies

  • User1090950853 posted

    Try this

    context.Response.WriteFile(context.Server.MapPath("files/" + last));


    Sunday, March 19, 2006 4:21 PM
  • User309311432 posted

    thanks for reply Kobipinhasov

    context.Response.ContentType = "audio/mpeg"

    context.Response.WriteFile("/myhandler/files/" + last);

    I solved the problem. It occurs because it writes the content of file to the output stream as html format but because this is a downloable file, the httphandler must write the content of file the output stream as zip or .mp3 whatever the file type is.

    Now, I can check the requests coming for my files not only aspx files.



    Monday, March 20, 2006 1:40 PM