I visit my ASHX file and output the PDF file perfectly. If I visit the same ASHX with a different query string (I add DateTime.Now.Ticks to the end of each visit), and I get this error:
The server cannot add an adder after sending HTTP headers.
My code is below:
copy.CloseStream = false;
document.Close();
var r = context.Response;
r.ExpiresAbsolute = DateTime.Now;
r.BufferOutput = true;
r.ContentType = "application/pdf";
r.AppendHeader("Content-Type", r.ContentType);
r.AppendHeader("Content-disposition", "inline; filename=" + context.Server.UrlEncode(formType.File_Name));
r.BinaryWrite(copyStream.ToArray());
r.StatusCode = 200;
r.End();
originalReader.Close();
copy.CloseStream = true;
copy.Close();
There is no other place in this code where headers are sent. You see all the interaction with the Response object.
I tried to use r.Flush();and r.End();I also tried not to send them if they are already there, but this causes other problems.
source
share