urlReferrer将在MVC Post controller Action Method中变为null
本文关键字:null Method Action 将在 MVC Post controller urlReferrer | 更新日期: 2023-09-27 18:01:27
我是张贴表单从一个mvc应用程序A到另一个mvc应用程序b
在B动作方法我得到urlReferer为空。
应用A代码:
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();
}
因为您的应用程序A没有托管。