0

We have an ASPX application that behaves oddly when rendering the page for the first time.

To put you in context:

MyWeb -> MyPaymentWebAplication.

We send our client to the payment site and we are suposed to get back to the Web an OK from the payment site.

MyPaymentWebAplication -> MyWeb.

Here is where the problem occurs.

We have a special page in our Web: GetResponseFromPaymentPage.aspx, This page, is only used to get the OK response from the payment so in theory, it always have to be rendered for the first time and by this, join (!IsPostBack).

The problem here is that the page in not joining here and instead jumps out and nothing executes so we dont get any confirmation.

Code here:

    try
        {

            HtmlForm frm = (HtmlForm)FindControl("frmRedireccion");

            NameValueCollection parametros = (NameValueCollection)Session[ConstantesSesion.SESSION_PARAMETERS_RETURNED];

            frm.Action = parametros["AppReturnURL"]; 

            foreach (string key in parametros.Keys)
            {
                if (((HtmlInputHidden)frm.FindControl(key)) != null)
                {
                    ((HtmlInputHidden)frm.FindControl(key)).Value = parametros[key];
                }
            }                



            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script language=Javascript>\n");
            sb.Append("  window.opener.name = 'MyParent'; ");
            sb.Append("  document.forms.namedItem('frmRedireccion').target = 'MyParent'; ");
            sb.Append(" document.forms.namedItem('frmRedireccion').submit(); ");
            sb.Append(" self.window.close(); ");
            sb.Append("</script>");

            ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());

        }
        catch (Exception ex)
        {
            ExceptionService.SetException("Excepción en el método " + MethodBase.GetCurrentMethod().Name, ex);
        }

Back to the Web, we should recive the parameters and start doing our things on the recently opened page.

    protected void Page_Load(object sender, EventArgs e)
{
    //We are writing these traces on DB!
    MyTraces con = new MyTraces();
    con.InsertTrace("Im a Trace!", "!We are in!", System.DateTime.Today, "1");
    //************************************************************


    if (!Page.IsPostBack) 
    {
       // These ones are not behing seen anywhere in DB
        con.InsertTrace("Im a Trace!", "!We are in step 2 Already!",  System.DateTime.Today,"2");

So, we supose that !Page.IsPostBack is not returning True, when it should be and by this, our second trace is not getting writen in DB.

¿Does anyone Know What could be causing this issue? We are thinking on any patch, update, or something else on our systems because we have no other explanations, this app has been running for a while whitout problems.

Elan Sanchez
  • 110
  • 1
  • 10
  • I am afraid the issue won't be visibile from the codes you provided, I suggest proceeding by elemination of portions of code by graduation and testing out, beginning from the master page if there is any and so on. Hope it helps. – Wail Jun 29 '17 at 10:43
  • Show us the code you are using to access `GetResponseFromPaymentPage.aspx`. – mjwills Jun 29 '17 at 11:00
  • Have a squiz at https://stackoverflow.com/questions/5650580/how-does-ispostback-technically-work and see how it identifies a post back. My guess is that the previous page has set `__PREVIOUSPAGE`. – mjwills Jun 29 '17 at 11:03
  • @mjwills we call it with the script you see in the first part of our code – Elan Sanchez Jun 29 '17 at 11:10
  • Can you view source and show us the contents (from the HTML) of the frmRedireccion form? – mjwills Jun 29 '17 at 11:20

1 Answers1

0

Im back with a solution.

Here is the block code that causes the trouble.

      System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script language=Javascript>\n");
        sb.Append("  window.opener.name = 'MyParent'; ");
        sb.Append("  document.forms.namedItem('frmRedireccion').target = 'MyParent'; ");
        sb.Append(" document.forms.namedItem('frmRedireccion').submit(); ");
        sb.Append(" self.window.close(); ");
        sb.Append("</script>");

        ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());

For some unknown reasons, when redirecting using this code, the freshly created page acts as if it were doing a postback instead of first time rendering.

We have no clue on what was causing this, we suspect it has something to do with some windows security patch but we cant probe it.

On this case, we solved this replacin this code with:

    Response.redirect();

We tweaked it a bit to make it do a POST instead of GET (Default) and its up and running.

Thx all for your time and help.

Elan Sanchez
  • 110
  • 1
  • 10