Home All Groups Group Topic Archive Search About
Author
20 Jan 2006 5:03 PM
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

Author
20 Jan 2006 5:25 PM
Sreejith Ram
Is this code to expire cache a part of Page_Load ?..

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

Show quote
"MattB" wrote:

> 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
>
Author
20 Jan 2006 7:22 PM
MattB
Sreejith Ram wrote:

> 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


Show quote
> "MattB" wrote:
>
>
>>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
>>
Author
21 Jan 2006 11:58 AM
Joerg Jooss
Hello MattB,

Show quote
> 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,
--
Joerg Jooss
news-re***@joergjooss.de

AddThis Social Bookmark Button