Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在IE 8中导出到Excel_C#_.net_Internet Explorer 8_Export To Excel - Fatal编程技术网

C# 无法在IE 8中导出到Excel

C# 无法在IE 8中导出到Excel,c#,.net,internet-explorer-8,export-to-excel,C#,.net,Internet Explorer 8,Export To Excel,我无法在IE 8中导出到excel。我不断得到以下信息: “IE无法从url下载filename.aspx。” “IE无法打开此internet站点。请求的站点不可用或找不到。请重试” 在我看来,好像是它忽略了https,并试图打开http,但我可能错了。 根据本文: 我的代码是: StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw);

我无法在IE 8中导出到excel。我不断得到以下信息: “IE无法从url下载filename.aspx。” “IE无法打开此internet站点。请求的站点不可用或找不到。请重试”

在我看来,好像是它忽略了https,并试图打开http,但我可能错了。 根据本文:

我的代码是:

 StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                gvResources.RenderControl(htw);

                Response.ClearContent();
Response.ClearHeaders()
                Response.AddHeader("Content-Disposition", "attachment; filename=AdHocReport.xls");
                Response.ContentType = "application/vnd.ms-excel";
                Response.Write(sw.ToString());
                Response.End();

我发现一条线索,建议您需要禁用缓存控制头

试一试:

 Response.Cache.SetCacheability(HttpCacheability.NoCache);
资料来源:|

此外:


…我希望能发现一些更深层次的理解,但我发现的仅此而已。

尝试去除内容配置中的空间,并尝试在文件名周围添加引号:

 Response.AddHeader("Content-Disposition", "attachment;filename=\"AdHocReport.xls\"");

是否有理由将字符串编写器与write一起使用,而不是流与binarywrite一起使用?

问题在于IIS应用程序池。已解决。

我刚刚能够解决此问题。我在
response.clear()之后添加了以下几行

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

可能的副本谢谢!这是非常相似的,但我并没有做同样的事情,在另一篇文章中导致错误的代码行-我没有;(我希望easyi最初没有编写代码,只是试图找出导出不起作用的原因。不幸的是,按照您的建议修改了标题,没有改变任何内容。