POST-REDIRECT-GET (PRG) is a design pattern that states that a POST request to the server should be answered with a REDIRECT response that points the user to a GET request what will yield some summary of the POST-ed data. To quote Wikipedia, When a web form is submitted to a server through an HTTP POST request, attempts to refresh the server response can cause the contents of the original POST to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.To avoid this problem, many web developers use the PRG pattern — instead of returning a web page directly, the POST returns a redirect. The HTTP 1.1 specification introduced the HTTP 303 („See other”) response code to ensure that in this situation, browsers can safely refresh the server response without causing the initial POST request to be resubmitted. In most cases, failure to implement PRG properly leads to user seeing an unfriendly warning message when trying to refresh the page with the form. If the user chooses to continue with the refresh operation (which they are naturally tempted to do), it can lead to them executing duplicate request – with results ranging from inconvenient (like registering two edits with the same data) to downright dangerous (like charging the payment twice). The solution, as we said, is to respond to POST request with a REDIRECT that points the user to a GET page. When the form in question is filled correctly, it’s as simple as returning a RedirectToPageResult from […]
Czytaj dalej