asp.net - 使用 IE 在 ASP.NEt 中强制下载 PDF

标签 asp.net internet-explorer firefox pdf google-chrome

因此,我使用了一些代码来强制下载我基于 ASP.Net 的项目。这段代码在 Firefox 和 Chrome 中有效,但由于某些奇怪的原因在 IE 中无效。更奇怪的是,它最初在所有三个中都有效,最近才停止在 IE 中工作。下面是我使用的代码,如果需要进行任何调整或者可能有什么问题,请告诉我。

 string path = MapPath(fname);
    string name = Path.GetFileName(path);
    string ext = Path.GetExtension(path);
    string type = "Application/pdf";
    Response.AppendHeader("content-disposition","attachment; filename=" + path);
    Response.WriteFile(path);
    Response.End();  

更多详情 这是修改后的代码,仍然不适用于 IE。

 string path = MapPath(fname);
    string name = Path.GetFileName(path);
    string ext = Path.GetExtension(path);
    string type = "Application/pdf";
    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType = type;
    Response.AddHeader("content-disposition","attachment; filename=" + path);
    Response.WriteFile(path);
    Response.End();  

最佳答案

您可能应该尝试将 mime 类型设置为“application/octet-stream”。如果您不希望特定的处理程序响应 mime 类型。

关于asp.net - 使用 IE 在 ASP.NEt 中强制下载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5582363/

相关文章:

java - Firefox Webdriver Selenium "No protocol specified"、Debian(Wheezy)、服务、脚本

c# - 如何使用 LINQ 在函数中定义返回类型?

asp.net - 将 JQuery Ajax 与 ASP.NET 混合使用 : is there any security risk

javascript - 如何将多个文件从服务器复制到 USB 驱动器

javascript - 我如何为所有浏览器使用 CSS.escape() 或等价物?

html - 这是一个错误吗? P 元素的边距超出包含的 div

html - 渲染一行后跟文本

css - Sifr 显示两次 - 仅限 IE?

javascript - Winwheel IE 8 Canvas

c# - Firefox 中的 WebSocket