Post Redirect Get in asp.net
I'm interested in implementing PRG in my website for some forms I've created. At present they postback to themselves, and obviously refreshing these pages posts the data in duplicate. Can anyone point me in the direction of a good tutorial of how I can code this i开发者_运维问答nto my site? I understand the logic but am not sure exactly where to start. Thanks
After you postback to the form you simply need to perform a redirect after the postback.
DoPostbackProcessing();
Response.Redirect("FormConfirmationPage.aspx");
As a very simple example, basically as long as you redirect (GET) to another page then the user cannot duplicate the postback. Of course if there are any errors in the forum you may not want to re-direct, but this is down to individual requirements.
EDIT: A good example of this is search, instead of posting back and then performing the search you would redirect and GET:
// Instead of performing search now we will redirect to ourselves with the criteria.
var url = "SearchPage.aspx?criteria=" + txtSearch.Text;
Response.Redirect(url);
This then redirects, the page then checks for a criteria query string and THEN performs the search, and when the user refreshes it searches again - plus they can bookmark the page for instant searching.
精彩评论