title: Post-Redirect-Get with ASP.NET
body: <p>How can i implement the <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get" rel="nofollow noreferrer">Post-Redirect-Get</a> pattern with ASP.NET?</p>
  
  <p>A button click performs some processing:</p>
  
  <pre><code>&lt;asp:Button id="bbLaunch" OnCommand="bbLaunch_Click" /&gt;
  </code></pre>
  
  <p>User clicks the button, the spacecraft is launched, the web-page redisplays. If the user presses F5, they get the warning:</p>
  
  <p><img src="https://i.stack.imgur.com/zwWIk.png" alt="enter image description here"></p>
  
  <p>The solution to the problem is the <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get" rel="nofollow noreferrer">Post-Redirect-Get</a> pattern.</p>
  
  <p>What is the method by which <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get" rel="nofollow noreferrer">PRG</a> can be implemented in ASP.NET?</p>
  
  <hr>
  
  <p>The question centers around the problems of:</p>
  
  <ul>
  <li>how can the <code>&lt;asp:Button&gt;</code> perform a <strong><code>POST</code></strong> to a place that isn't its original form?</li>
  <li>what becomes of the <strong>ViewState</strong> when you post to a form that doesn't read view state?</li>
  <li>what becomes of the <strong>ViewState</strong> when you redirect to the "real" aspx web form?</li>
  <li>is <strong>ViewState</strong> fundamentally incompatible with <strike>ASP.net</strike> Post-Redirect-Get?</li>
  <li>is ASP.net fundamentally incompatible with <strong>Post-Redirect--Get</strong>?</li>
  <li><em>how</em> (i.e. what code) do you redirect to the "real" aspx web form?</li>
  <li><em>how</em> (i.e. what url) do you redirect to the "real" aspx web form? A relation question mentions <code>Response.Redirect(Request.RawUrl);</code></li>
  <li><em>when</em> (i.e. in what event handler) do you redirect to the "real" aspx web form?</li>
  <li>the related questions raise issues of <em>how</em> you post form data. There is the implication that HTML <em>forms</em> cannot be used - and all form data must be added to the query string. Is this true? If so, why? If not, why not? <strong>Can</strong> a browser put form data in a query string? </li>
  <li>a related question mentions <code>Server.Transfer</code>. Using <code>Server.Transfer</code> is completely wrong, and in no way solves the Post-Redirect-Get problem (because there is no <em>Redirect</em>). Correct?</li>
  <li>what code change has to happen in the <code>aspx</code> or <code>aspx.cs</code> file to support PRG? Presumably, at the very least, the code must be changed to <code>post</code> somewhere besides <code>MyPage.aspx</code>.</li>
  </ul>
  
  <p>In other words: <strong>How do you do Post-Redirect-Get in ASP.net?</strong></p>
  
  <p><strong>Note</strong>: ASP.net (i.e. not ASP.net MVC)</p>
  
  <h2>See also</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/919516/how-do-i-implement-the-post-redirect-get-pattern-in-asp-net-webforms">How do I implement the Post/Redirect/Get pattern in asp.net WebForms?</a></li>
  <li><a href="https://stackoverflow.com/questions/331277/how-do-i-use-the-post-redirect-get-a-k-a-redirect-after-post-with-asp-net">How do I use the “Post/Redirect/Get” a.k.a. “Redirect after Post” with asp.net</a></li>
  </ul>