【发布时间】:2010-09-29 01:39:18
【问题描述】:
我有一个页面重定向,它在使用 WebClient 和 StringBuilder 将字符串写入 MSword 文档后运行。
HttpContext.Current.Response.Write(strHTMLContent);
this.Page.Response.Redirect("http://www.google.com");
HttpContext.Current.Response.End();
但是字符串永远不会被写入(或者它没有机会写入),因为重定向会立即发生。
我怎样才能让我的重定向只在字符串写入发生之前运行?
谢谢大家
这是用于生成 MSWord 的代码:
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
【问题讨论】:
-
你到底想在这里做什么?在用户的浏览器中显示 strHTMLContent?或者将他们重定向到google.com?
-
尝试在 MSWord 文档中显示 strHTMLContent(可行),然后将浏览器重定向到 google.com
-
见上面输出到 MSWord 的代码
标签: c# redirect response.redirect