Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Duplicate headers received from server' Error in Chrome 16 with EPPlus 2.9

I'm playing around with EPPlus 2.9 and for some reason I'm getting Duplicate headers received from server errors when I try to download single .xlsx files using Chrome 16 (It works fine in IE9).

I'm using this tutorial and I've narrowed down the problem to this line of code:

        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"));

My useragent:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7

I read on this Chrome forum page that Chrome doesn't like commas (,) in Content-Disposition headers and they should be replaced with semicolons (;).

Anybody got any ideas or getting the same errors?

like image 263
Greg Avatar asked Jan 26 '12 07:01

Greg


2 Answers

I'm dumb, DateTime.Now.ToString("R") produces Thu, 26 Jan 2012 02:05:44 GMT

I fixed it by doing this:

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);

I'm used to IE being cranky and Chrome playing nice...

like image 123
Greg Avatar answered Nov 01 '22 01:11

Greg


I had the same issue and I also had the semi colon after attachment correctly. I found my issue was having commas in the filename. So I replaced them with dashes.

like image 28
kyleb Avatar answered Nov 01 '22 02:11

kyleb