我有一个调用页面方法的 JavaScript 函数,如下所示:
function openFile(file) {
PageMethods.LoadFile(file);
}
[System.Web.Services.WebMethod]
public static void LoadFile(string fileName)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/binary";
var filePath = @"C:\MyFiles\" + fileName;
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", fileName));
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}
page 方法抛出以下异常:
Microsoft JScript 运行时错误:Sys.Net.WebServiceFailedException:服务器方法“LoadFile”失败并出现以下错误:System.Threading.ThreadAbortException--线程被中止。
我怎样才能解决这个问题?