【问题标题】:Resource interpreted as Other but transferred with MIME type undefined. error for IE (Asp.net Website)资源解释为“其他”,但以未定义的 MIME 类型传输。 IE 错误(Asp.net 网站)
【发布时间】: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


【解决方案1】:
  Response.Cache.SetCacheability(HttpCacheability.NoCache);

通过从代码中删除这一行来解决。

【讨论】:

    【解决方案2】:

    这可能有效:

    Response.ClearHeaders();
    Response.AddHeader("Cache-Control", "no-store, no-cache");
    

    Source link

    【讨论】:

    • 尝试启用缓冲区Response.Buffer = true; 另外,尝试application/vnd.ms-excel
    猜你喜欢
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    • 2010-11-26
    • 2016-03-30
    • 1970-01-01
    • 2020-05-06
    • 2017-03-19
    • 1970-01-01
    相关资源
    最近更新 更多