发送HTTP标头后,服务器无法设置内容类型

Gur*_*epS 8 c# asp.net sharepoint-2010

我在以下代码(ContentType行)上收到错误(服务器无法在发送HTTP标头后设置内容类型.).我应该改变什么?

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(PervasiveConstants.DownloadZipLocation) + ";");
response.TransmitFile(PervasiveConstants.DownloadZipLocation);
response.Flush();
response.End();  
Run Code Online (Sandbox Code Playgroud)

这是在Sharepoint 2010 webpart内.

Dhw*_*hah 6

尝试设置response.BufferOutput = true;.设置response变量后立即执行此操作.

  • 我使用了** System.Web.HttpResponse响应= System.Web.HttpContext.Current.Response; ** ** Response.BufferOutput = true; **但是我仍然遇到相同的错误。 (2认同)