我想返回一个pdf文件作为对某些按钮点击的响应。 我成功发送了pdf文件,但是当我尝试通过浏览器保存时,它不会让我将其保存为.pdf文件(但作为.aspx文件)
这里是代码:
Dim myWebClient As WebClient = New WebClient()
Dim myDataBuffer As Byte() = myWebClient.DownloadData(LocalImageURL) ' LocalImageURL is some path to a pdf file
Response.ContentType = "application/pdf"
esponse.BinaryWrite(myDataBuffer)
Response.Flush()
Response.End()
如果我在写入字节数组之前还要添加以下行:
Response.AddHeader("content-disposition", "attachment;filename=report.pdf")
它可以解决问题,但问题是页面仍然卡住(看起来它仍然等待服务器响应)