Cross-site validation, page loads to quickly

William Mitchell 1 Reputation point

I have an application written in PHP that runs on one server and when a user clicks a button, inserts a record into a database using a security token (GUID) then opens a new browser frame that navigates to a different ASP.NET Web Forms website using the GUID as a query parameter value. During page load of the ASP.NET site, a web service call is made back to access the same database to validate the request is valid. The issue I am having is, the ASP.NET page sometimes loads before the PHP site has had time to insert the record thus the ASP.NET site informs the user the request is not valid. If I refresh the ASP.NET page, the record has thus had time to be written and all works fine. Some of the time, it works as it should but it needs to work reliably all the time of course.

I am seeking a way to tell the ASP.NET page to delay for maybe 1 or 2 seconds during the initial page load, I suppose checking for Page.IsPostBack = false and if it is the initial page load, to put the delay in before a call is made to validate the request during that same page load lifecycle.

For anyone wondering, I have not had any luck trying to insert the control record on the PHP website and then delay before calling the ASP.NET during the button click event on that site.

Thanks for any tips or suggestions!

A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 51,346 Reputation points

    That isn't the correct solution to me. Stalling your app just because of a timing issue punishes everyone. I see a couple of options.

    1. The PHP app should insert the record into the DB and then open the browser window. Since it doesn't call the other site until after the insert then there shouldn't be a timing issue. You said it didn't work for you but you didn't say why. If the DB insert is async then you'll need to wait for the task to complete. Posting code could be useful here.
    2. Have the second site check for the record. If it doesn't find it then poll for some reasonable amount of time (say 30 seconds) before failing the call.

    There are other options as well but these seem the simplest.

    0 comments No comments

  2. William Mitchell 1 Reputation point

    @Michael Taylor ,

    Thanks for those suggestions and you are entirely correct, if I could get the PHP to work properly, there would be no need to add a delay on the ASP.NET side. The initial issue was the way the PHP app was coded. It was calling a PHP function on the button click that did the insert of the record to the database and then built out a javascript function in the page which got passed the url to navigate to. That was causing an issue with most browsers because apparently navigating to another website within script during a postback versus being directly handled by the a button click causes the browser to block as a pop-up. Since that was going to cause a lot of issue for internal and external visitors to the site, the code was changed to perform the record insert by making a PHP function call and then directly making the navigation into another frame all within the button onclick even but after that change, I guess the second call to navigate is not waiting for the PHP call to finish thus the issue of sometimes the ASP.NET page showing before the record has finished being inserted to the database. I am guessing there might be an easy solution on the PHP side as well, I just don't know it as well as the ASP.NET side thus my initial thought to try and put in a fix there. Thanks.

  3. William Mitchell 1 Reputation point

    @Michael Taylor ,

    Thanks again and yes, I suppose that was where I initially ran into issues. I was trying to do a redirect within a single PHP function call after the record was inserted using the header function but that did not seem to be allowing me to open a new frame when redirecting and other suggestions on PHP sites for how to redirect involved using javascript and thus when I started going that route, that is when the pop-up issue started. Maybe I should ask on a PHP-specific forum if there is a way directly from a PHP function to open a new browser frame. Then everything could be synchronous as I had originally tried and of course would always have the record existing to validate the other site against.

    0 comments No comments