Kevin Donn
Kevin Donn

Reputation: 528

Trouble with Response.TransmitFile and Apache

I've got a chunk of ASP.Net 2.0 code in the Page Load handler that looks basically like this:

        Response.Clear();
        Response.ContentType="application/pdf";
        Response.TransmitFile("foo.pdf");
        Response.End();

It works fine with all browsers when running through either IIS or Cassini. But when I try to run it through Apache using mod_aspdotnet.so (which I really need to support and generally has no weirdness), I get a variety of bad behavior. With Chrome, Firebird, and IE, I get an "OK 200" page saying, "The server encountered an internal error or misconfiguration and was unable to complete your request." With Safari, it winds up reloading the page.

I've tried it with other file types, different ContentType, WriteFile instead of TransmitFile, using AddHeader to supply Content-Length and Content-Disposition, and BufferOutput. In short, I'm running out of ideas on how to even go about figuring out what's wrong. Any ideas appreciated.

kd

Upvotes: 0

Views: 202

Answers (1)

Kevin Donn
Kevin Donn

Reputation: 528

I finally got this to work. I don't expect many (any?) other people to be in this boat, but if you are, here's what works:

    Response.Clear();
    Response.ContentType="application/pdf";
    f=new FileStream(targetFile, FileMode.Open);
    byte[] b=new byte[(int)f.Length];
    f.Read(b, 0, f.Length);
    f.Close();
    Response.BinaryWrite(b);
    Response.Flush();

Upvotes: 2

Related Questions