How do I use the "Post/Redirect/Get" a.k.a. "Redirect after Post" with asp.net
Asked Answered
R

2

4

Doing a refresh after certain action in asp.net seems to make them happen again even when that action doesn't make sense (think double delete). The web way to deal with this situation is to redirect after a post to get a clean version of the page that can be refreshed without reposting an action to the webserver. How can I do this with ASP.NET

Rafferty answered 1/12, 2008 at 16:7 Comment(1)
I'm using .NET Framework 2.0 but would be interested in answers as they apply to all framework versionsRafferty
N
5

I have a feeling there is a deeper problem I'm not getting but here goes. In your postback event:

// the post handling logic, e.g. the click event code
Response.Redirect(Request.RawUrl);
Novah answered 1/12, 2008 at 16:26 Comment(1)
That should be Response.Redirect(Request.RawUrl, false); to finish processing and avoid the application killing sessions, etc.Punchy
A
-1

Use Server.Transfer method.

The Server.Transfer method has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

http://www.developer.com/net/asp/article.php/3299641

Anaphylaxis answered 1/12, 2008 at 17:27 Comment(2)
So how would that prevent double delete or double submit?/Mcwhorter
@Mcwhorter It wouldn't. You can't use Server.Transfer, as P-R-G requires the client to be sent a redirect status code.Sheepish

© 2022 - 2024 — McMap. All rights reserved.