Response.TransmitFile和Apache的问题

时间:2011-11-14 19:19:21

标签: asp.net apache

我在页面加载处理程序中有一大块ASP.Net 2.0代码看起来基本上是这样的:

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

通过IIS或Cassini运行时,它适用于所有浏览器。但是当我尝试使用mod_aspdotnet.so(我真的需要支持并且通常没有任何怪异性)通过Apache运行它时,我会遇到各种不良行为。使用Chrome,Firebird和IE,我收到一个“OK 200”页面,上面写着“服务器遇到内部错误或配置错误,无法完成您的请求。”使用Safari,它可以重新加载页面。

我尝试过其他文件类型,不同的ContentType,WriteFile而不是TransmitFile,使用AddHeader提供Content-Length和Content-Disposition,以及BufferOutput。简而言之,我对如何解决问题的想法已经不多了。任何想法都赞赏。

KD

1 个答案:

答案 0 :(得分:2)

我终于开始工作了。我不希望很多(任何?)其他人都在这艘船上,但如果你在,这就是有效的:

    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();