我知道这种问题在很多论坛上被问过很多次,但让这个问题变得陌生的是,它适用于本地和服务器上的一个模块,但不适用于另一个模块。
让我更清楚。
我正在为一个模块导出一个 excel 表,例如使用以下代码的 CS
public void ExportToExcel(string fileName, GridView gv)
{
try
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
HttpContext.Current.Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
}
}
并导出另一个列表,例如具有相同代码的零售商。我在本地调试,对于第二个模块,它给出了一个异常
ThreadAbortException
但是一个记录列表。
正如这里建议的那样,我使用HttpContext.Current.ApplicationInstance.CompleteRequest
了但得到了意想不到的结果(整个页面都被暴露了)