我来自iframe的回复网址替换了我完整的浏览器网址

时间:2019-06-15 17:15:35

标签: javascript c# html asp.net iframe

我遇到的问题是我的Iframe响应URL代替了我的父(浏览器)URL,而不是Iframe内部的开口。

我有我的“应用程序”页面(default.aspx)页面,可以从浏览器访问该页面。在该页面中,我通过传递3个URL加载了iframe

  1. ./ Response?Stauts = cancel
  2. ./ Response?Status =拒绝
  3. ./ Response?Status = confirmed

将代码发布到iFrame URL的代码片段。

<%@ Page Language="C#" %>
        <script runat="server">
        bool _postLoadCustom = false;
                protected void Page_Load(object sender, EventArgs e)
                {
                    if (IsPostBack)
                        return;
                    string CANCELURL = Request.Params["CANCELURL"];
                    string ERRORURL = Request.Params["ERRORURL"];
                    string REDIRECTURL = Request.Params["REDIRECTURL"];
                    {
                        NameValueCollection data = new NameValueCollection();
                        data.Add("__CANCELURL", CANCELURL);
                        data.Add("__ERRORURL", ERRORURL);
                        data.Add("__REDIRECTURL", REDIRECTURL);
                        RedirectAndPOST(this.Page,"https://IframeURL/Content", data);
                    }
                }
                #region RedirectAndPost
                public static void RedirectAndPOST(Page page, string destinationUrl,NameValueCollection data)
                {
                    string strForm = PreparePOSTForm(destinationUrl, data);
                    page.Controls.Add(new LiteralControl(strForm));
                }
                    private static String PreparePOSTForm(string url, NameValueCollection data)
                {
                    string formID = "PostForm";
                    StringBuilder strForm = new StringBuilder();
                    strForm.Append("<form id=\"" + formID + "\" name=\"" +
                                   formID + "\" action=\"" + url +
                                   "\" method=\"POST\">");

                    foreach (string key in data)
                    {
                        strForm.Append("<input type=\"hidden\" name=\"" + key +
                                       "\" value=\"" + data[key] + "\">");
                    }
                    strForm.Append("</form>");
                    //Build the JavaScript which will do the Posting operation.
                    StringBuilder strScript = new StringBuilder();
                    strScript.Append("<script language='javascript'>");
                    strScript.Append("var v" + formID + " = document." +
                                     formID + ";");
                    strScript.Append("v" + formID + ".submit();");
                    strScript.Append("<" + "/script>");
                    return strForm.ToString() + strScript.ToString();
                }
            #endregion
            </script>
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title></title>
        </head>
        <body>
          Loading...
        </body>
        </html>

当我完成Iframe的旅程并单击Submit(iframe按钮)时,我获得了我通过Iframe传递给第三方服务的网址之一。从该URL中提取信息(状态)。我收到的响应URL应该重定向到Iframe,但它正在替换当前的URL(default.aspx)。

下面的代码是我的响应页面,我用来从响应URL中提取信息并将其存储到会话中。

    <%@ Page Language="C#"  %>
    <!DOCTYPE html>
<script runat="server">
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            else
            {
                string url = HttpContext.Current.Request.Url.AbsolutePath;
                string status = Request.QueryString["status"].Split('-')[0];
                string sessionID = Request.QueryString["status"].Split('-')[1];
                string exampleServerUrl = ConfigurationManager.AppSettings["ServerURL"];
                String sessionName = "ProductBase_1_0_0_0";
                string request =
                        @"
                        <server><requests>
                        <resumeSession sessionID=""{0}""/>
                        <Session.setElementRq path=""data/policyAdmin/policynotes/FITSStatus"" value=""{1}""/>
                        </requests></server>";
                request = string.Format(request, sessionID, status);
                string response = this.HTTPPost(exampleServerUrl, request);
            }
        }

        private string HTTPPost(string url, string requestXML)
        {
            string result = null;
            System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            wr.Timeout = 90000;
            wr.ServicePoint.ConnectionLimit = 10;
            wr.Method = "POST";
            wr.ContentType = "text/xml";
            byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(requestXML);
            System.IO.Stream strm = wr.GetRequestStream();
            strm.Write(byteArray, 0, byteArray.Length);
            strm.Close();
            System.Net.WebResponse resp = wr.GetResponse();
            System.Text.Encoding enc = Encoding.GetEncoding("utf-8");
            System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream(), enc);
            result = reader.ReadToEnd();
            reader.Close();
            resp.Close();
            return result;
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    <body>
         <form id="paypageresponce" runat="server" method="post">
                <!--#include file="Response.html"-->
               <label>Payment in progress...</label>
         </form>
    </body>
    </html>

我包含了Response.html页面,从中调用了javascript函数以自动单击“应用程序”按钮。

我一直在努力地寻找解决方案,但是没有运气。我尝试替换iFrame网址,但由于服务的安全性而不允许使用。

我已经调试了代码,并达到指向当我单击iframe的提交按钮时的位置,我的response.aspx网址替换了我的default.aspx。

任何人都可以让我知道为什么响应URL替换了重定向到IFrame的实例。

0 个答案:

没有答案