Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Newsletter
Links
Tech News
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
Avoiding Refresh
Welcome,
Guest
. Please
login
or
register
.
September 10, 2010, 04:42:12 PM
11491
Posts in
1260
Topics by
496
Members
Latest Member:
Beerdernill
Home
Help
Search
Login
Register
Experts Round Table Network
|
Programming
|
.NET
|
Avoiding Refresh
« previous
next »
Pages:
[
1
]
Print
Author
Topic: Avoiding Refresh (Read 1904 times)
rodri
Offline
Posts: 1
Avoiding Refresh
«
on:
February 02, 2006, 06:52:13 AM »
hello everyone,
I have a page that has a button, which inserts a row in a DataBase. If after have pressed the button I refresh the page, the refreshing makes a new insert (which obviosly is not wished). I heard that I could avoid this situation using HTTP headers that disable the cache, but i couldn't figure this out until now.
Could anyone give a piece of advise?
thanks a lot.
Logged
Anonymous
Guest
Avoiding Refresh
«
Reply #1 on:
February 02, 2006, 07:31:44 AM »
The way I understand the problem is that pressing the button makes a POST request to the webserver.
Refreshing the page after the results re-issues the POST request.
There are many techniques available to stop this.
For me, the most obvious one is to simple not inject repeat data. The application should be able to determine if the data has already been posted and to not repost it.
Another way is to pass the user a page which is basically a redirect to the results page.
If they then refresh, the redirect is the page being reloaded (or the results page) and not the original POST.
The cache controller available are not guaranteed in all cases and knowing that, relying on them is dangerous.
Logged
IM
Moderator
Offline
Posts: 12
Avoiding Refresh
«
Reply #2 on:
February 02, 2006, 07:59:26 AM »
Using a session (or just some cookie) would seem to be one way around this.
But I'd personally go for RQuadling's suggestion of
"pass the user a page which is basically a redirect to the results page."
Logged
VGR
Mentor
Offline
Posts: 718
Avoiding Refresh
«
Reply #3 on:
February 02, 2006, 12:32:06 PM »
Yes. In fact, as this is not a pure .Net question, it happens that it was asked - and answered I'm afraid - on this very same site, in the "web dev" section (or the like)
The "usual" solution is your script done this way :
// inits
// get $_POST[] data (for example)
// if the FORM was submitted
// check data
// if correct
// write to DB
// redirect to same page (thus clearing up the POST data, so that a F5/Refresh doesn't do anything
// if not, complain
// endif
// endif
// display FORM and current content
that's ONE solution, the one which works the best IMHO
An other solution is to play with the HTTP headers about "cache-control", but this is unreliable IMHO
In PHP you would use simply issue the line
header("Cache-Control: none, must-revalidate");
or the like, before any HTML is output.
This problem is also discussed in various places on EEE.org
regards
Logged
techie overlord, answers all kind of questions on
http://www.europeanexperts.org
rodri
Offline
Posts: 1
Avoiding Refresh
«
Reply #4 on:
February 03, 2006, 07:00:29 AM »
well thanks for all the suggestions posted. I tried with the meta tags:
Code:
<meta http-equiv="expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache;no-store;must-revalidate" />
but i didn't have any good result.
about my app, i got tree grids on the same page, each one makes a new insert with its corresponding button, thats why I can't send the user to another results page.
well, about VGR's suggestion, i understood that i shoud validate the data right?, but what shold be the best way:
* to do this against a DataBase or
* by comparing with a cookie.
I think that both have good & bad issues.
I'll try to solve this problem and I'll tell later.
thanks a lot.
Logged
Esopo
Governing Council Member
Offline
Posts: 75
Avoiding Refresh
«
Reply #5 on:
February 17, 2006, 05:24:58 AM »
Have you considered redirecting the page to itself before displaying the results so that all cache is lost?
Works like this:
1. A page request is made with POST (and/or GET)
2. The page process it and before showing the results it sends a blank page redirecting to itself
3. the page is reloaded and loses any cache. If the redirect was sent through server headers it happens instantly and the user won't notice a thing.
Alternatively you don't need to redirect to the same page. If for any reason you are having problems adapting the page to receive the self-redirection, you can just move the code to another page and redirect to that. The ultimate goal is to end with a page that did not receive any data so that users can't resend the form by refresing the page.
To send a redirect by headers with asp.net:
Response.Redirect("page2.aspx")
Hope that helps.
Logged
SSirica
Moderator
Offline
Posts: 2
Avoiding Refresh
«
Reply #6 on:
February 27, 2006, 12:43:52 PM »
Sounds like a job for "Page.IsPostBack". When it is a postback, ie pressing the button, save the record. When it's not, don't.
Logged
He is your friend, your partner, your defender, your dog. You are his life, his love, his leader. He will be yours, faithful and true, to the last beat of his heart. You owe it to him to be worthy of such devotion!
Pages:
[
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
===> 2006
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
===> 2006
===> 2007
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com