以下代码(ContentType
行)出现错误(服务器无法在发送HTTP标头后设置内容类型)。我应该改变什么?服务器在发送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();
这是在Sharepoint 2010 webpart中。
这是所有服务器的一般“问题”。一旦程序开始生成内容,标题应发送给客户端,无法更改。 为了在程序中的任何位置设置标题,您需要启用输出缓冲或稍微。它在Apache/php中被称为“输出缓冲”,但在其他服务器中应该有类似的东西。 – kirilloid 2012-02-20 12:14:19
为什么从'ClearContent'开始?如果响应已经*有*内容,那么你的代码可能在这个过程中运行得太晚了。 – 2012-02-20 13:17:05