导出到excel工作在本地但不在服务器上

我知道很多论坛上这样的问题很多次被问到,但是让这个问题变得陌生的事情是,它在本地和服务器上的一个模块工作,而不是另一个模块。

让我更清楚。

我出口一个模块的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) { } } 

并导出另一个列表说,零售商使用相同的代码。 我debugging本地和第二个模块,它是一个例外

ThreadAbortException但是一个logging列表。

正如我在这里build议我使用HttpContext.Current.ApplicationInstance.CompleteRequest但得到意想不到的结果(整个页面expoted)