我正在从一个mvc应用程序A向另一个mvc应用程序B发布表单。
在B动作方法中,我将urlReferer设为null。
申请代码:
private string BuildPostForm(string Url, string PostData)
{
try
{
string formId = "__PostForm";
StringBuilder strForm = new StringBuilder();
strForm.Append(string.Format("<form id=\"{0}\" name=\"{0}\" action=\"{1}\" method=\"POST\">", formId, Url));
string MID = "9820359248";
strForm.Append("<input type=\"hidden\" name=\"" + "merchantRequest" + "\" value=\"" + PostData + "\">");
strForm.Append("<input type=\"hidden\" name=\"" + "MID" + "\" value=\"" + MID + "\">");
//if (PostData != null)
//{
// foreach (string key in PostData)
// {
// strForm.Append("<input type=\"hidden\" name=\"" + key + "\" value=\"" + PostData[key] + "\">");
// }
//}
// strForm.Append("<div id=\"loading\"><p class=\"top1 loading-txt\"> Processing Payment </p><img id=\"loading-image\" src=\"../../Images/ajax-loader.gif\" alt=\"Loading...\" /><p class=\"top2 loading-txt-bottom\">Please do not press on refresh button</p></div>");
strForm.Append("<div class=\"wrapper\"><div class=\"login_wrap loading_wrap\"><div class=\"logo\"> </div><br><p class=\"top1 loading-txt\"> Processing Payment </p><div class=\"sk-spinner sk-spinner-wandering-cubes loading_tp\"><div class=\"sk-cube1\"></div><div class=\"sk-cube2\"></div></div><p class=\"top2 loading-txt-bottom\">Please do not press on refresh button</p></div></div>");
strForm.Append("</form>");
strForm.Append("<link rel=\"stylesheet\" href=\"../../Content/css/PinePGRedirect.css\" type=\"text/css\"/>");
strForm.Append("<link rel=\"stylesheet\" href=\"../../Content/css/loader.css\" type=\"text/css\"/>");
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language=\"javascript\">");
strScript.Append(string.Format("var v{0}=document.{0};", formId));
strScript.Append(string.Format("v{0}.submit();", formId));
strScript.Append("</script>");
return strForm.ToString() + strScript.ToString();
}
catch (Exception ex)
{
return null;
}
}
public override void ExecuteResult(ControllerContext context)
{
var strHtml = "";
strHtml = BuildPostForm(m_Url, m_strPostData);
context.HttpContext.Response.Write(strHtml);
}
申请B代码:
[HttpPost]
public ActionResult Index(FormCollection formCollection)
{
try
{
Uri uri1 = HttpContext.Request.UrlReferrer;
string str = Request.ServerVariables["HTTP_REFERER"];
}
catch(Exception ex)
{
}
return View();
}
将uri1和str取为null。
答案 0 :(得分:0)
因为您的应用程序A未托管。