How can i implement the Post-Redirect-Get pattern with ASP.NET?
A button click performs some processing:
<asp:Button id="bbLaunch" OnCommand="bbLaunch_Click" />
User clicks the button, the spacecraft is launched, the web-page redisplays. If the user presses F5, they get the warning:
The solution to the problem is the Post-Redirect-Get pattern.
What is the method by which PRG can be implemented in ASP.NET?
The question centers around the problems of:
- how can the
<asp:Button>
perform aPOST
to a place that isn't its original form? - what becomes of the ViewState when you post to a form that doesn't read view state?
- what becomes of the ViewState when you redirect to the "real" aspx web form?
- is ViewState fundamentally incompatible with
ASP.netPost-Redirect-Get? - is ASP.net fundamentally incompatible with Post-Redirect--Get?
- how (i.e. what code) do you redirect to the "real" aspx web form?
- how (i.e. what url) do you redirect to the "real" aspx web form? A relation question mentions
Response.Redirect(Request.RawUrl);
- when (i.e. in what event handler) do you redirect to the "real" aspx web form?
- the related questions raise issues of how you post form data. There is the implication that HTML forms cannot be used - and all form data must be added to the query string. Is this true? If so, why? If not, why not? Can a browser put form data in a query string?
- a related question mentions
Server.Transfer
. UsingServer.Transfer
is completely wrong, and in no way solves the Post-Redirect-Get problem (because there is no Redirect). Correct? - what code change has to happen in the
aspx
oraspx.cs
file to support PRG? Presumably, at the very least, the code must be changed topost
somewhere besidesMyPage.aspx
.
In other words: How do you do Post-Redirect-Get in ASP.net?
Note: ASP.net (i.e. not ASP.net MVC)