[英]label not updated in System.Threading.ThreadAbortException
在我的頁面中,我正在嘗試下載文件。 該文件已成功下載,但出現System.Threading.ThreadAbortException。 所以我在嘗試捕獲塊中處理了該問題,並將錯誤標簽設置為空白,但頁面中沒有更新。
catch (System.Threading.ThreadAbortException)
{
lblErrorMsg.Text = "dfdf";
}
catch (Exception ex)
{
lblErrorMsg.Text = "Error while processing you request :<br> Erorr Description : " + ex.Message;
}
這是我的寫入文件功能
public static void WriteFile(string nameOfFile, string fileContent, HttpResponse writer)
{
writer.ClearHeaders();
writer.ClearContent();
writer.ContentType = "text/xml";
writer.AppendHeader("Content-Disposition", "attachment; filename=" + nameOfFile);
writer.Write(fileContent);
writer.Flush();
writer.End();
}
有人可以告訴我為什么在調試代碼時,即使標簽位於system.thread.threadabortexceptiopn的Catch塊下,標簽也不設置為空白?
發生ThreadAbortException是因為您通過調用Response對象的End()方法過早關閉了Response。 這也解釋了為什么現在寫頁面內容為時已晚。 這不是一個很煩人的錯誤,但是最好進行整潔的處理。
只需檢查以下答案, 為什么Response.Redirect會導致System.Threading.ThreadAbortException? 或如何避免Response.End()“線程被中止”在Excel文件下載期間發生異常,以及與Response和ThreadAbortException相關的其他答案,以了解它並通過編寫更好的文件下載代碼來正確處理(根據您的用法)。
另外請注意,對於頁面和頁面上的某些內容(例如標簽)完全重寫的響應流沒有什么意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.