我使用此代码来下载文件,但它会引发错误。请帮我处理它。为什么我的代码抛出线程中止错误?
线程正在中止。
protected void Download_Click(object sender, EventArgs e)
{
try
{
string filePath = Convert.ToString(Attachment);
string fullFilePath = ("../../SiteImages/" + "donald.jpg");
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(fullFilePath) + "\"");
Response.ContentType = ContentType;
Response.TransmitFile(fullFilePath);
//MngLogs.InsertAuditsInfo("Tender downloaded via" + " " + MngLogs.PageName, MngLogs.UserMacAddress, MngLogs.UserIPAddress, UserID, "Download");
//Response.End();
}
catch (Exception ex)
{
Utility.Msg_Error(Master, ex.Message);
}
}
你从哪里得到错误? 'Reponse.End()'总是抛出一个'ThreadAbortException'。看看[这个](http://stackoverflow.com/questions/20988445/how-to-avoid-response-end-thread-was-being-aborted-exception-during-the-exce)和[this] (http://stackoverflow.com/questions/5834049/what-causes-thread-was-being-aborted-exception-to-happen-at-random-and-show-th)后。 –
是相同的地方,我删除它,但它仍然没有下载文件 – Cuckoo
并不抛出错误,但仍然不下载文件 – Cuckoo