【问题标题】:How to spawn and post to a page and then redirect to another如何生成并发布到页面然后重定向到另一个页面
【发布时间】:2012-08-24 02:12:21
【问题描述】:

从我的 asp.net 页面,我正在使用 System.Web.HttpContext.Current.Response.Write 生成一个页面。完成后,我想重定向到另一个页面。它不起作用。如果我最后有 Response.Redirect,那么它会立即重定向而不产生页面。部分代码如下:

string targetUrl = ConfigurationManager.AppSettings["URL"].ToString();


System.Web.HttpContext.Current.Response.Write(
"<form name='newForm' target='_blank' method=post action=" + targetUrl + " >");

System.Web.HttpContext.Current.Response.Write(
string.Format("<input type=text name=\"txtAcctNumber\" value=\"{0}\">",
                                  ViewState["GroupNumber"].ToString()));

System.Web.HttpContext.Current.Response.Write(
 string.Format("<input type=text name=\"txtAmountDue\" value=\"{0}\">",       txtAmountDue.Text));

 System.Web.HttpContext.Current.Response.Write("</form>");
 System.Web.HttpContext.Current.Response.Write("</body>");

 Response.Write("<SCRIPT LANGUAGE='JavaScript'>document.forms[0].submit();</SCRIPT>");
 Response.Clear();
 Response.Redirect("~/PremiumPayment/InvoiceSearch.aspx");

谢谢

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    Response.Redirect 导致 ThreadAbourException 向客户端发送 http 302 响应。 它用于立即重定向。

    您应该使用元标记向您的用户显示一条消息,然后重定向。

    <meta http-equiv="refresh" content="10;URL=http://mysite/PremiumPayment/InvoiceSearch.aspx" />
    

    这将在 10 秒后将您的用户重定向到新页面。

    【讨论】:

      猜你喜欢
      • 2016-05-07
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 2017-06-05
      • 2017-06-08
      • 1970-01-01
      相关资源
      最近更新 更多