473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to expire an ASP.NET page?

Hi,

I've been searching and testing and have not yet found the answer I'm
looking for.

I have an ASP.NET (vb) application with an ecommerce function. When
the user submits the page, I DON'T want them to be able to click on the
'BACK' button and get back to the form - they may inadvertently
re-submit the page and get charged again. I WANT them to get the "Page
has expired" message.

I used to be able to do something like this with the META "Expires" tag
in classic ASP, but that doesn't seem to work with .NET.

I've tried...

Page.Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

....in my Page_Load but the most they've been able to do is clear out
the form. They will not force the "Page is expried", which is what I
want.

Can someone please give me the definitive answer on manually expiring a
web form page in ASP.NET?

Thanks,

ShusteS

Jul 20 '06 #1
4 2806

"Scott Shuster" <sc***********@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
The things that you have already tried are legitimate, however, you must
understand that browsers still do what they want to do and cache content
locally and not respect the HTTP headers that are sent down. I'm not sure if
there is any more you can do.
Hi,

I've been searching and testing and have not yet found the answer I'm
looking for.

I have an ASP.NET (vb) application with an ecommerce function. When
the user submits the page, I DON'T want them to be able to click on the
'BACK' button and get back to the form - they may inadvertently
re-submit the page and get charged again. I WANT them to get the "Page
has expired" message.

I used to be able to do something like this with the META "Expires" tag
in classic ASP, but that doesn't seem to work with .NET.

I've tried...

Page.Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

...in my Page_Load but the most they've been able to do is clear out
the form. They will not force the "Page is expried", which is what I
want.

Can someone please give me the definitive answer on manually expiring a
web form page in ASP.NET?

Thanks,

ShusteS
Jul 20 '06 #2
I'm guessing at the code - but try:

Response.Cache.SetExpires(DateTime.Parse(DateTime. Now.ToString()))
Response.Cache.SetCacheability(HttpCacheability.Pr ivate)
--
Regards

John Timney (MVP)
"Scott Shuster" <sc***********@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I've been searching and testing and have not yet found the answer I'm
looking for.

I have an ASP.NET (vb) application with an ecommerce function. When
the user submits the page, I DON'T want them to be able to click on the
'BACK' button and get back to the form - they may inadvertently
re-submit the page and get charged again. I WANT them to get the "Page
has expired" message.

I used to be able to do something like this with the META "Expires" tag
in classic ASP, but that doesn't seem to work with .NET.

I've tried...
Page.Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

...in my Page_Load but the most they've been able to do is clear out
the form. They will not force the "Page is expried", which is what I
want.

Can someone please give me the definitive answer on manually expiring a
web form page in ASP.NET?

Thanks,

ShusteS

Jul 20 '06 #3
Hi,

Thanks for the post.

I have tried everything, including this suggestion, and the most that
it will do is clear out the form (cache) so that when the user clicks
on the BACK button, the form is empty.

Nothing I've done has actually expired the form so that the page won't
show at all, which is what I'm trying to acheive.

Thanks,

Scott Shuster
John Timney (MVP) wrote:
I'm guessing at the code - but try:

Response.Cache.SetExpires(DateTime.Parse(DateTime. Now.ToString()))
Response.Cache.SetCacheability(HttpCacheability.Pr ivate)
--
Regards

John Timney (MVP)
"Scott Shuster" <sc***********@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I've been searching and testing and have not yet found the answer I'm
looking for.

I have an ASP.NET (vb) application with an ecommerce function. When
the user submits the page, I DON'T want them to be able to click on the
'BACK' button and get back to the form - they may inadvertently
re-submit the page and get charged again. I WANT them to get the "Page
has expired" message.

I used to be able to do something like this with the META "Expires" tag
in classic ASP, but that doesn't seem to work with .NET.

I've tried...
Page.Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

...in my Page_Load but the most they've been able to do is clear out
the form. They will not force the "Page is expried", which is what I
want.

Can someone please give me the definitive answer on manually expiring a
web form page in ASP.NET?

Thanks,

ShusteS
Jul 21 '06 #4
Thus wrote Scott,
Hi,

I've been searching and testing and have not yet found the answer I'm
looking for.

I have an ASP.NET (vb) application with an ecommerce function. When
the user submits the page, I DON'T want them to be able to click on
the 'BACK' button and get back to the form - they may inadvertently
re-submit the page and get charged again. I WANT them to get the
"Page has expired" message.
Generally speaking, that's impossible. The HTTP 1.1 spec clearly says:

"History mechanisms and caches are different. In particular history mechanisms
SHOULD NOT try to show a semantically transparent view of the current state
of a resource. Rather, a history mechanism is meant to show exactly what
the user saw at the time when the resource was retrieved.

By default, an expiration time does not apply to history mechanisms. If the
entity is still in storage, a history mechanism SHOULD display it even if
the entity has expired, unless the user has specifically configured the agent
to refresh expired history documents."

Many browser do handle the concepts "history list" and "local cache" as one
entity, others don't. Some even change their behavior depending on specific
Cache-Control headers or the use of HTTPS.
I used to be able to do something like this with the META "Expires"
tag in classic ASP, but that doesn't seem to work with .NET.
If whatever you've tried to achieve with a META tag worked for you in ASP,
it will work in ASP.NET as well. This is a client specific behavior.
I've tried...

Page.Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
To prevent caching, the first line usually suffices.

But in an internet scenario where you have no control over your users' browsers,
this approach is bound to fail. If you want to prevent duplicate form submits,
either

a) use redirect-after-post -- after processing the form submit, use HttpResponse.Redirect()
to send the user to the next page. The browser will only record the redirect's
GET in its history, not the POST. The drawback of this approach is another
roundtrip to the client for each form submit.

b) use a synchronizer token. Each web form includes a token (e.g. a GUID
or random number) that can be used only for one form submission. If you receive
a post back with an unexpected token, you can handle the duplicate submission
as you see fit. Here's a sample implementation: http://tinyurl.com/lnx9w.
The drawback of this approach is that some browser will warn the user of
duplicate form submission, which many wrongly think of as an error message.
Thus, the user experience isn't really great: The user clicks back, thr browser
displays a warning, the user submits again away, and finally the application
displays a warning or an error after detecting the duplicate submisson --
that's not really nice.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jul 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
3
by: martin | last post by:
Hi, I am storing a dataset in cache, which is happening fine. I can easily retrive it at postback from the cache, cast it to a dataset and reuse it. However I have specified that the cache...
3
by: Joey Powell | last post by:
This message was originally posted to the aspnet.security newsgroup, but no one there has ever heard of this before. That is why I am posting this message here, so that more people will see it... ...
13
by: Veeresh | last post by:
I am using .Net 1.1. How to expire an .aspx page? I think I have to use HttpCachePolicy class for this. But not sure how to use and where to this code to work. Is it in Page_load event. Thanks...
2
by: karunakar | last post by:
Hi All I dont want to expire the applicatoion Once login the application i dont want to expire the application Presently iam doing using cookies this is not working fine Please help me out ...
4
by: TCORDON | last post by:
How can I expire a page so if a user click back for example the page shows message "This Page has expired" or better yet a peronalized "Page expired" page. TIA!
23
by: Phil Powell | last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY AND THUS EXPIRE function setCookie(name, value, days, docObj)...
3
by: bbgraph | last post by:
Does anyone have a suggestion for doing this with a date function rather than the typical content=(number of seconds) function? I have an events page that I'd like to expire on a certain date and,...
2
by: Chris Davoli | last post by:
How do you expire pages so that the user can't hit the back button on his browser in Internet Explorer? I've tried the meta tag in the header that has an expires = 0 and also in vb.net...
0
by: aspineux | last post by:
setacl and getacl look to be already "Cyrus" specific (according the doc), why not to extend imaplib a little bit more ? Here are some code I wrote and tested to support cyrus "expire" that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.