Duplicate headers received from the server

Duplicate headers received from the server

The response from the server contained duplicate headers. This problem is usually the result of an improperly configured website or proxy. Only a website or proxy administrator can fix this problem.

Error 349 (net :: ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Several separate Content-Disposition headers were received. This is not allowed to protect against attacks with an HTTP response.

I found this error when exporting to pdf in chrome.

Response.Buffer = false; Response.ClearHeaders(); string ext = objProp.PACKAGEFILENAME.Substring(objProp.PACKAGEFILENAME.LastIndexOf(".")); string ext1 = ext.Substring(1); Response.ContentType = ext1; Response.AddHeader("Content-Disposition", "target;_blank,attachment; filename=" + objProp.PACKAGEFILENAME); const int ChunkSize = 1024; byte[] binary = objProp.PACKAGEDOCUMENT; System.IO.MemoryStream ms = new System.IO.MemoryStream(binary); int SizeToWrite = ChunkSize; for (int i = 0; i < binary.GetUpperBound(0) - 1; i = i + ChunkSize) { if (!Response.IsClientConnected) return; if (i + ChunkSize >= binary.Length) SizeToWrite = binary.Length - i; byte[] chunk = new byte[SizeToWrite]; ms.Read(chunk, 0, SizeToWrite); Response.BinaryWrite(chunk); Response.Flush(); } Response.Close(); 

How to fix it?

+99
google-chrome pdf
Nov 27 '12 at 6:17
source share
5 answers

These were a little old, but were high in google ranking, so I thought that I would choose the answer received from Chrome, display in pdf format, duplicate headers received from the server

Basically my problem also was that the file name contains commas. Substitute a comma to remove them, and everything should be in order. My function to create a valid file name is below.

  public static string MakeValidFileName(string name) { string invalidChars = Regex.Escape(new string(System.IO.Path.GetInvalidFileNameChars())); string invalidReStr = string.Format(@"[{0}]+", invalidChars); string replace = Regex.Replace(name, invalidReStr, "_").Replace(";", "").Replace(",", ""); return replace; } 
+196
Feb 12 '13 at 16:10
source share

The server SHOULD place double quotes around the file name, as mentioned by @cusman and @Touko in their responses.

For example:

 Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\""); 
+83
Sep 15 '14 at 8:46
source share

For me, the question about the comma was not in the file name, but as below: -

Response.ok (streamingOutput, MediaType.APPLICATION_OCTET_STREAM_TYPE) .header ("content-disposition", " attachment, file_name = your_file_name"). build ();

I accidentally put a comma after attachment. Having received this solution, replacing the comma with a semicolon.

+4
Jun 28 '17 at 18:34
source share

Just put a couple of double quotes around your file name as follows:

this.Response.AddHeader ("Content-disposition", $ "attachment; filename = \" {outputFileName} \ "");

+2
Feb 29 '16 at 22:54
source share

Double quotes around the file name in the header are standard for MDN web documents. The omission of quotation marks creates many opportunities for problems arising from characters in the file name.

0
Jan 13 '19 at 11:38
source share



All Articles