views:

241

answers:

3

hello,

<%@ OutputCache Duration="3600" VaryByParam="none" %>    

protected void Page_Load(object sender, EventArgs e)
{Label1.Text = DateTime.Now.ToString();}

If, after I compiled this newly created application, browser B1 is first to request Cache.aspx, then the time displayed on received page is 10.16:20. If, after say 10 seconds, I refresh B1’s Cache.aspx( by clicking a button to cause a postback), then time 10.16.30 will show up, and on all subsequent postbacks 10.16.30 will always be displayed ( until 1 hour elapses ). If few minutes after B1 first requested Cache.aspx, browser B2 also requests the same page, then upon receiving the page for the first time, B2’s Cache.aspx will display time 10.16.20, and on all subsequent B2’s postbacks time 10.16:30 will be displayed instead.

A) So it appears that Asp.net generates two cached versions of Cache.aspx ( thus code is executed twice ), one cached page is given to browsers that request Cache.aspx for the first time, and second cached page is given to browsers which only refresh their Cache.aspx?

B) Since my book never mentioned such a behavior, I’m wondering if you get the same behavior or is my Net environment again “unique”?

C) Creating two copies of same page ( thus executing the code twice ) seems like a waste of time, so why does Asp.Net operate like that – there must be some reasoning/benefits behind it?

thank you

+2  A: 

A complete guess, but presumably the cache is isolated by the overall request (query string args, etc)... even though the "none" turns off the key/value pairs, presumably a "GET" is simply still counted as different to a "POST"???

Try using simple links (<a href...> etc) rather than ASP.NET buttons.

Marc Gravell
A: 

A complete guess, but presumably the cache is isolated by the overall request (query string args, etc)... even though the "none" turns off the key/value pairs, presumably a "GET" is simply still counted as different to a "POST"???

Have no idea what you just said, but:

If Cache.aspx has both "< a href... >" and a button on a page, then on first request time displayed is 10.20.30, and if I use "< a href... >" for postbacks, Cache.aspx displays 10.20.30. But if 10 minutes later I click on a button, then Cache.aspx displays time 10.30.30. Now if postback is caused by "< a href... >", time displayed is always 10.20.30, if by button, then time is 10.30.30

Urgent - Is this happening just with me or you guys have same problems?

SourceC
Marc is saying that any Asp Control will do a Postback which is a POST command while the default (first page or <a> ) will do a GET
Henk Holterman
You can tell by using this: Label2.Text = Request.RequestType + ' ' + Request.RawUrl;
Henk Holterman
I see. But why would GET/POST be used as parameters ( similar to the way we choose parameters with VaryByParam attribute), since I'd assume caching should only cache based on the criteria we choose?! Is there a way we can turn it off?
SourceC
A: 

if i try if (ispostback) begin response.cache.setcachebility(nocache) end

then the button click updates the label every time.