[英]Downloading files using ASP.NET .ashx modules
我有一個帶有iframe的ASP.NET頁面,用於在此頁面上顯示一些pdf報告。 當用戶從下拉列表中選擇報告類型時,我將報告數據所需的內容添加到ASP.NET會話中,並將iframe的屬性“src”更改為生成.pdf報告的.ashx模塊地址。 但是如果沒有安裝用於查看瀏覽器中的.pdf文件的Adobe glug-in,則瀏覽器建議保存報告文件,並且建議文件的名稱為“HandlerName.ashx”。 但我想建議瀏覽器保存名為“Report.pdf”的文件。 我可以這樣做嗎? 有沒有解決方法?
在ashx文件中添加以下標題:
context.Response.AddHeader("content-disposition", "attachment;filename=PUTYOURFILENAMEHERE.pdf");
context.Response.ContentType = "application/pdf";
嘗試內聯內容處理,但我必須檢查:
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "inline; filename=" + name );
Use
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=Report.PDF");
Response.WriteFile(Server.MapPath("~/YourPath/Report.PDF"));
Response.End();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.