views:

157

answers:

3

Is there a built-in asp.net way to conditionally serve pages, for example I want the following logic:

If there is a session data I generate a page, if there is no session data I serve the cached page.

I am only interested in knowing about a built-in asp.net mechanism for this. If it does not exist I am probably going to simply cache my page manually and decide whether to serve it or not for each request, based on the session data availability.

+2  A: 

I don't think there is built-in support (like varyByParam) for generating fresh output for users with Session Data.

As you suggest, I would recommend manually caching the pages. I would probably determine the user's Session state in the PreRequestHandlerExecute event handler in the Global.asax and then maybe set:

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Andrew Corkery
A: 

At the risk of karmabombing, I really don't like this approach to caching.

For me if a GET request is made, then a server should respond to that in good faith. Caching at a page level should be controlled by http headers because the primary goal is not to get the redundant request at all - you don't want to allocate server/bandwidth resources full stop.

Caching objects which are resources involved in making up a page I can totally get behind, but I can't see great arguments for caching a page wholesale.

Respect the headers.

annakata
Technically entity tags (HTTP 1.1) could be used here without going against what you mentioned (which I agree with).
Richard Szalay
sure, as could HEAD requests, but it's about support - I'm saying the concept is flawed from the get go
annakata
A: 

You might want to look at the substitution control (http://geekswithblogs.net/ranganh/archive/2005/05/04/39003.aspx) new in .NET 2.0, however it might not be exactly what you are after.

Kane