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?
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With