为什么在IE 8没有内容处理标头的工作? [英] Why doesn't Content-Disposition header work in IE 8?

查看:114
本文介绍了为什么在IE 8没有内容处理标头的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想流的文本文件(CSV)的反应,以下code完美的作品在Firefox 3中,但是当我使用IE浏览器,它看起来要下载的实际.aspx页面中,并抱怨该文件内容不匹配文件扩展名或类型。如果我再选择要下载的文件,无论如何,它正确下载CSV数据并打开它在Excel中。我在做什么错了?

  DataTable的DT = ExtensionsProvider.ListPrivateCallCostsForCsv(reportFilter.BusinessUnit,reportFilter.StartDate,
                                                             reportFilter.EndDate);
    Response.Clear();
    将Response.Buffer =真;
    Response.ContentType =TEXT / CSV;
    Response.AddHeader(内容处置,文件名=+ GetExportFileName());
    DataTableHelper.WriteCsv(DT,Response.Output,FALSE);
    到Response.End();


解决方案

  Response.AddHeader(内容处置,文件名=+ GetExportFileName());

应该是:

  Response.AddHeader(内容处置,附件;文件名=+ GetExportFileName());

如果没有主内容处置价值,IE浏览器将只使用URL的后一部分 - something.aspx - 作为文件名

(以上假设 GetExportFileName()返回剥夺大部分标点符号的消毒文件名。可以作为标记或在IE中带引号的字符串头参数去什么是一个问题一些烦恼;见this有关详细信息,问题

I'm trying to stream a text file (CSV) to the response, and the following code works perfectly in Firefox 3, but when I use IE, it looks like it wants to download the actual .aspx page, and complains that the file contents don't match the file extension or type. If I then choose to download the file anyway, it correctly downloads the CSV data and opens it in Excel. What am I doing wrong?

    DataTable dt = ExtensionsProvider.ListPrivateCallCostsForCsv(reportFilter.BusinessUnit, reportFilter.StartDate,
                                                             reportFilter.EndDate);
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "text/csv";
    Response.AddHeader("Content-Disposition", "filename=" + GetExportFileName()); 
    DataTableHelper.WriteCsv(dt, Response.Output, false);
    Response.End();

解决方案

Response.AddHeader("Content-Disposition", "filename=" + GetExportFileName());

Should be:

Response.AddHeader("Content-Disposition", "attachment;filename=" + GetExportFileName());

Without a main Content-Disposition value, IE will just use the trailing part of the URL — something.aspx — as a filename.

(The above assumes GetExportFileName() returns a sanitised filename stripped of most punctuation. What can go in a header parameter as token or quoted-string in IE is a matter of some annoyance; see this question for details)

这篇关于为什么在IE 8没有内容处理标头的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆