Reputation: 2052
I'm trying to generate a PDF using a memory stream. When clears the headers, it threw Server cannot clear headers after HTTP headers have been sent
. Here is my code snippet.
Context.Response.Clear();
Context.Response.ClearHeaders();
Context.Response.ClearContent();
System.IO.MemoryStream st = new System.IO.MemoryStream();
st = (MemoryStream)levyStream;
byte[] b = st.ToArray();
Context.Response.AppendHeader("Content-Disposition", "inline; filename="+MyFilename);
Context.Response.AppendHeader("Content-Length", b.Length.ToString());
Context.Response.BufferOutput = true;
Context.Response.ContentType = "application/pdf";
Context.Response.Charset = "";
Context.Response.OutputStream.Write(b, 0, (int)st.Length);
Context.Response.Flush();
st.Close();
I have attached an error in response object along with this.
Regards, Aruna
Upvotes: 1
Views: 4507
Reputation: 424
It appears you are using IIS 7. If so, you need to change the application pool type from classic to integrated. The integrated pipeline mode is IIS 7 specific.
Upvotes: 1