Is it possible to remove postback information during page load?

  • Thread starter Thread starter steve.chambers
  • Start date Start date
S

steve.chambers

Here's the short version of this question:

When loading a page if Page.IsPostback is true, is there any way of
removing the POST parameters so the page would be loaded as a normal
GET request instead?

And here's the longer version...

I've recently added some code to a web application to prevent old
postbacks from being submitted e.g. in order to stop the dangerous
possibility of a delete operation from happening twice simply by
navigating back to an old page with POST parameters. In practice this
was implemented by detecting old postbacks in the OnLoad event and
then redirecting to the same page as a GET instead of a POST rather
than displaying a message to the user (since they probably would want
to do this anyway and would only be confused by any kind of error
message about an old postback). This is now working but the only
slight problem is that there are now 2 entries in the history for the
same page due to the redirect to self - am using SmartNavigation so
this doesn't happen elsewhere. Ideally would like to remove the second
entry from the history. The redirect happens from the server side so a
javascript window.replace() can't be used here. The only way I can
think of doing it is not to actually redirect when an old postback is
detected but instead to remove the postback information and load the
page normally.

Hope that's clear!

Any suggestions gratefully received...

Cheers
Steve
 
I think your solution is rather clever and shows strong thinking out side of
the box, but I am not certain it is easily maintainable. And you have
already found an issue with it.

Checking history for a page is not the best way to avoid duplicate submits.
One way to do this is to remove the history by placing history in the future
when the page is hit. Then the person can never go back with the back
button. Another might be to cache some information to be certain the form
submit is never duplicated. You can clear this value if someone GETs the
page, so they can enter again. I have also seen placing a specific value in
a hidden field that changes on each GET. You then only need to cache this
value server side and see if it is submitted again. I would imagine there is
a way to clear out the form with JavaScript, as well, although I have never
attempted it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top