Back button issues

M

MattB

I have an asp.net 1.1 eCommerce application that has a product page
where the user can select from many different options that affect the
price of the main product. I've implemented this with either a
RadioButtonList or a CheckBoxList that does a postback so I can display
the current price as the user changes options. It works pretty well, but
can do some odd things if the user navigates to the page with the back
button.
I've read up on this quite a bit, and found the following code block to
add to my codebehind to help reduce issues with using the back button:

Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1)
Response.Expires = 0
Response.CacheControl = "no-cache"

When I use this code on a page that doesn't use auto postbacks, it does
what I want, and that is to display a warning from the browser that the
content is expired.

But on my page that uses all the auto postbacks, the back button just
takes me back to the last postback state and the browser doesn't display
the expired content warning. Can anyone tell me why, or even better how
to make the page not cache even if I use those auto postback controls?
Thanks!

Matt
 
G

Guest

Is this code to expire cache a part of Page_Load ?..

Placing this in page load should expire cache on every post back..
 
M

MattB

Sreejith said:
Is this code to expire cache a part of Page_Load ?..

Yes it is, and it's not in a If Not IsPostBack block either.
Placing this in page load should expire cache on every post back..

I would have thought the same as you say, but that's not how it seems to
behave.
If I'm debugging and put a breakpoint in that bit of code (first code in
Page_Load), when I use the back button after a postback, my breakpoint
is never hit. So it looks like the Page_Load event isn't firing in these
cases.

Any more ideas?

Thanks for the reply!

Matt
 
J

Joerg Jooss

Hello MattB,
I have an asp.net 1.1 eCommerce application that has a product page
where the user can select from many different options that affect the
price of the main product. I've implemented this with either a
RadioButtonList or a CheckBoxList that does a postback so I can
display
the current price as the user changes options. It works pretty well,
but
can do some odd things if the user navigates to the page with the back
button.
I've read up on this quite a bit, and found the following code block
to
add to my codebehind to help reduce issues with using the back button:
Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1)
Response.Expires = 0
Response.CacheControl = "no-cache"

These are ASP legacy support APIs. The proper way in ASP.NET to control caching

Response.Cache.SetCacheability(HttpCacheability.NoCache);
When I use this code on a page that doesn't use auto postbacks, it
does what I want, and that is to display a warning from the browser
that the content is expired.

But on my page that uses all the auto postbacks, the back button just
takes me back to the last postback state and the browser doesn't
display the expired content warning. Can anyone tell me why, or even
better how to make the page not cache even if I use those auto
postback controls? Thanks!

I strongly recommend against trying to control browser navigation with cache
prevention. This is neither intended by the HTTP spec, nor is there a standard
approach to implement such a feature across all browsers for all cases. If
a back button click is harmful to your application, you should consider implementing
the Redirect-After-Post pattern.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top