c# - 资源解释为其他但传输时未定义 MIME 类型。 IE 错误(Asp.net 网站)

标签 c# asp.net download cross-browser

enter image description here

当我尝试从 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 interpreted as Other but transferred with MIME type undefined。错误但下载了文件,但 IE 抛出图像中显示的错误,我该怎么办,谢谢。

当我使用 Visual Studio 运行网站时,我可以在 IE8 中下载文件,但是当我尝试从上传到服务器的网站下载文件时,出现上述错误,错误仅在 IE 中8.

我尝试打开和关闭 IE 浏览器兼容模式,即使这样我也会收到同样的错误。

这是我的头部内容

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

最佳答案

  Response.Cache.SetCacheability(HttpCacheability.NoCache);

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

关于c# - 资源解释为其他但传输时未定义 MIME 类型。 IE 错误(Asp.net 网站),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8139084/

相关文章:

c# - 从 Entity Framework 中的实体获取 DbContext

c# - 字符串 HTML 中的双引号

c# - linux下使用iphlpapi.dll的方法 "GetAdaptersInfo"

.net - 如何让 .NET 先在本地文件夹而不是 GAC 中查找程序集?

asp.net - 为什么我在 asp.net 中收到数据库连接错误?

ios - 在swift 5中获取目录中的文件名

javascript - 在我的 View 中显示以数组字节为单位的图像

javascript - 编码下载功能

android - 在没有下载管理器或第三方库的情况下在连接不良时加载文件

c# - LINQ to SQL 是否总是默认使用事务?