在C#中调用Response.End()后重定向到另一个页面

Eva*_*ins 6 c# gridview response.redirect web-applications response

我正在将webview导出为ex​​cel,在Web应用程序中使用.Net 4.0,页面加载,需要生成文件,然后将页面重定向到调用页面.我遇到了问题,因为我导出到excel的代码如下:

gvSummary.Style.Add("font-size", ".6em");
    Response.Clear();
    string attachment = "attachment; filename=filename.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    gvSummary.GridLines = GridLines.Horizontal;
    gvSummary.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
Run Code Online (Sandbox Code Playgroud)

我知道如果我在.End()之前放置Response.Redirect(),我将被重定向但是文件永远不会生成,如果我在.End()之后放置Response.Redirect()我得到文件但没有重定向.

上面编写的代码在生成文件时效果很好,但是在生成文件之后,我仍然看不到我的加载动画,因为我无法突破页面.有任何想法吗?

ILy*_*Lya 9

我建议添加重定向标头.像这样的东西:

Response.AddHeader("Refresh", "3; url=index.html");
Run Code Online (Sandbox Code Playgroud)

其中3是延迟时间,index.html是url,您需要重定向到