user34537
user34537

Reputation:

Will redirect avoid double posting?

Probably not but i want to ask. Will redirect avoid double posting? I know there are better ways to avoid it but how do most double post happen? from my understanding its when the current page doesnt load and the user hits refresh, not bc of clicking post multiple times. I figure redirect info are so small that when the user hits refresh it will just try to load the new page and not resent the POST data.

Its just a very easy and fast solution, i just wanted to know if its highly effective or not?

Upvotes: 2

Views: 856

Answers (4)

Jeff Sternal
Jeff Sternal

Reputation: 48623

Yes, redirecting to avoid double posting is so common and so effective that the technique has a name, "Post-Redirect-Get." It will also make your ASP.NET code cleaner, since your pages won't need to handle both gets and posts. No more of this:

if (!this.IsPostBack) {
    // Do one thing for gets
} else {
    // Do something else for posts
}

The only drawback is that it can complicate the display of status and error messages.

Upvotes: 5

FWH
FWH

Reputation: 3223

It's a good thing to avoid accidental double posting.

It's even a best practice, and many MVC frameworks provide easy ways to do it.

It also prevents users being annoyed because they can't refresh a page without resending data.

Upvotes: 1

Jacob
Jacob

Reputation: 78890

Yes, it works for that purpose.

Upvotes: 0

leppie
leppie

Reputation: 117280

I think that approach works in most success cases. For failures, it gets a bit ugly.

Upvotes: 0

Related Questions