我正在使用以下代码来下载文件,但我认为Response.End
始终会导致Exception
。这是我的应用程序行为的成本吗?如果是,如何获得下载文件的替代方法。我尝试使用Thread.ResetAbort()
来处理异常,但这会导致不需要的额外数据添加到文件
try
{
DownloadFiles();
Response.End();
}
catch (ThreadAbortException)
{
// Thread.ResetAbort();
}
catch (GSException ex)
{
Response.ClearHeaders();
hdnResult.Value = ex.Message;
// ClientScript.RegisterStartupScript(this.Page.GetType(), "checkDownloadError", "window.parent.checkDownloadError('" + ex.Message + "');", true);
}
catch (Exception)
{
Response.ClearHeaders();
hdnResult.Value = "Oops! Something unexpected happened. Please try again later";
//ClientScript.RegisterStartupScript(this.Page.GetType(), "checkDownloadError", "window.parent.checkDownloadError('Oops! Something unexpected happened. Please try again later');", true);
}