我在玩EPPlus 2.9,由于某些原因,当我尝试使用Chrome 16下载单个Duplicate headers received from server文件时,出现.xlsx错误(在IE9中可以正常工作)。

我正在使用this tutorial,并将问题缩小到以下代码行:

        Response.AppendHeader("Content-Disposition",
        "attachment; " +
        "filename=\"ExcelReport.xlsx\"; " +
        "size=" + fileBytes.Length.ToString() + "; " +
        "creation-date=" + DateTime.Now.ToString("R") + "; " +
        "modification-date=" + DateTime.Now.ToString("R") + "; " +
        "read-date=" + DateTime.Now.ToString("R"));

我的用户代理:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7

我在this Chrome forum page上读到,Chrome浏览器不喜欢, header 中的逗号(Content-Disposition),应将其替换为分号(;)。

有人有任何想法或遇到相同的错误吗?

最佳答案

我很笨,DateTime.Now.ToString("R")产生Thu, 26 Jan 2012 02:05:44 GMT
我通过执行此操作来修复它:

String timestamp_without_commas = DateTime.Now.ToString("R").Replace(",","");

Response.AppendHeader("Content-Disposition",
    "attachment; " +
    "filename=\"ExcelReport.xlsx\"; " +
    "size=" + fileBytes.Length.ToString() + "; " +
    "creation-date=" + timestamp_without_commas + "; " +
    "modification-date=" + timestamp_without_commas + "; " +
    "read-date=" + timestamp_without_commas);

我已经习惯了IE会胡思乱想,Chrome会很好玩...

关于asp.net - 带有EPPlus 2.9的Chrome 16中的“从服务器接收到重复的 header ”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9014860/

10-10 01:02
查看更多