因此,我使用了一些代码来强制下载我基于 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/