以下代碼(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