2011-11-14 69 views
0

我已经得到的ASP.Net 2.0代码块在页面加载处理程序,基本上是这样的:麻烦与Response.TransmitFile和Apache

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

通过运行时,它正常工作与所有浏览器无论是IIS或卡西尼。但是当我尝试使用mod_aspdotnet.so(我真的需要支持并且通常没有怪异)通过Apache运行它时,我会遇到各种不良行为。使用Chrome,Firebird和IE浏览器时,我会看到一个“确定200”的页面,内容为“服务器遇到内部错误或配置错误,无法完成您的请求。”使用Safari,它会重新加载页面。

我试过用其他文件类型,不同的ContentType,WriteFile代替TransmitFile,使用AddHeader提供Content-Length和Content-Disposition,以及BufferOutput。简而言之,我对如何解决错误的想法很少。任何想法赞赏。

kd

回答

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