【发布时间】:2010-10-23 14:48:06
【问题描述】:
我将值从 ASP.NET 网站发布到完全不同的网站(实际上是 Paypal)。我通过向用户返回一个页面来实现这一点,该页面已经编写了所有隐藏的表单输入,然后是一个自动提交表单的 Javascript 函数。
这个过程应该是无缝的,但是空白页在它显示的几秒钟内很明显。用户只需单击 ASP.NET 页面上的按钮,然后被重定向到 Paypal。但是我在中间注入了这个空白页面,以便在中间发布变量(如账单信息、订单项目等变量)。空白页太明显了,我希望有更好的方法来做这件事,或者提出让这个过程看起来更无缝的建议。
这是我正在使用的方法:
public static void PostToRemote(string url, Dictionary<string, string> inputs)
{
if (String.IsNullOrEmpty(url))
return;
HttpContext context = HttpContext.Current;
//CREATE UNIQUE FORM NAME
string formName = "remoteform1";
//ERASE ENTIRE RENDER OF CURRENT PAGE
context.Response.Clear();
//OUTPUT SINGLE FORM TO POST DATA
context.Response.Write("<html><head></head>");
//ON LOAD, PAGE WILL POST FORM TO NEW URL
context.Response.Write(String.Format("<body onload=\"document.{0}.submit()\">", formName));
context.Response.Write(String.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", formName, "post", url));
//ADD PARAMETERS TO PAGE TO POST
foreach (var item in inputs)
{
context.Response.Write(String.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", item.Key, item.Value));
}
context.Response.Write("</form>");
context.Response.Write("</body></html>");
context.Response.End();
}
有什么建议可以让用户更加无缝或更加愉快吗?谢谢!
【问题讨论】:
-
为什么不直接从带有按钮的页面发布该表单?
标签: c# javascript .net asp.net paypal