【发布时间】:2011-12-29 15:48:56
【问题描述】:
当我尝试从 Chrome 下载时它工作正常,但在 IE 8 中它没有下载它显示上面的错误,
protected void btn_ExcelDownload_Click(object sender, EventArgs e)
{
Grid_UserTable.Columns[0].Visible = false;
string subject = lbl_Subj.Text;
Response.Buffer = true;
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Cache-Control", "no-store, no-cache");
Response.AddHeader("content-disposition", "attachment;filename=" + subject + "-Status.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Grid_UserTable.RenderControl(htmlWrite);
rptList.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
当我在 chrome 中使用开发人员工具时,它将 Resource 解释为 Other 但以未定义的 MIME 类型传输。错误但是下载了文件,但是 IE 抛出了如图所示的错误,我该怎么办,谢谢。
当我使用 Visual Studio 运行网站时,我可以在 IE8 中下载文件,但是当我尝试从服务器上传的网站下载文件时,出现上述错误,该错误仅在 IE 中8.
我尝试打开和关闭 IE 浏览器兼容模式,即使这样我也收到同样的错误。
这是我的头内容
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
【问题讨论】:
-
我测试了你的代码,它在 IE8 中对我有用。您使用的是哪个版本的 IE?
-
它在本地主机上工作,当上传到服务器时出现上述错误。
标签: c# asp.net download cross-browser