gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:15:10 24 4
gpt4 key购买 nike

我正在将 gridview 导出到 excel,在 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();

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

上面编写的代码在生成文件时工作得很好,但是当文件生成后我仍然无法看到我的加载动画,因为我无法跳出页面。有什么想法吗?

最佳答案

我建议添加一个重定向 header 。像这样:

Response.AddHeader("Refresh", "3; url=index.html");

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

关于c# - 在 C# 中调用 Response.End() 后重定向到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3676734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com