我正在尝试使用内存流生成PDF。清除标题后,它会抛出Server cannot clear headers after HTTP headers have been sent
。这是我的代码片段。
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();
我在响应对象中附加了一个错误。
此致 阿鲁娜
答案 0 :(得分:1)
您似乎正在使用IIS 7.如果是这样,您需要将应用程序池类型从经典更改为集成。集成管道模式是IIS 7特定的。