[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

How to set output page cache for all pages at once?

Jason

5/24/2006 3:43:00 PM

Is there an easy way to set the output page cache for all pages in an app at
once?

It seems like the only way to set the page output cache is to use the
@OutputCache directive in each page, or to do it programatically. I've also
tried to do it programatically within a master page, but that doesn't seem to
work either.

Is there any way to do this globally for every page in an app?
2 Answers

stcheng

5/25/2006 5:21:00 AM

0

Hi Jason,

Thank you for posting.

As for the OutputCache configuration you mentioned, I'm wondering whether
you're developing the application upon ASP.NET 1.x or ASP.NET 2.0. Based
on my research, ASP.NET 1.x only provide declarative or programmatic
interfaces for configuring outputCache, and declarative approach need us to
specify the outputCache setting in the @OutputCache directive in aspx
template.

In ASP.NET 2.0, there does provide new configuration setting in the
application config file(web.config or machine.config ). Those settings can
help define some global level cache profiles(somewhat like cache setting
template), and we can apply these template profile to any page in our web
application. You can get the detailed info in the following msdn reference:

#Cache Configuration in ASP.NET
http://msdn2.microsoft.com/en-us/library/ms1...

However, the above approach still require us to add the profile setting in
each individual aspx page like:

<%@ OutputCache CacheProfile="MyCacheProfile1" %>

So far there still lack a configuration setting which can directly put an
outputCache for all the pages in the application. If you do want to apply
OutputCache on all the pages or a certain group of pages in an ASP.NET
application, you can consider use code to programmatically set the Page
Response's Cache properties. e.g:

============================
void Application_BeginRequest(object sender, EventArgs e)
{

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);
...............
}
============================

The above code use the appliation's global class's "BeginRequest" event to
set the cache properties on the HttpResponse. Also, based on my research,
the @OutputCache directive used in aspx template actually is compiled as an
internal function which is called by the dynamic compiled page class in a
initialize function named "FrameworkInitialize()", we can use reflector to
check the dynamic generated page assembly to verify this. And If you would
like to programmatically configure the cache properties, you can reference
to the autogenerated code:

=====================
protected override void FrameworkInitialize()
{
this.StyleSheetTheme = "White";
base.FrameworkInitialize();
this.__BuildControlTree(this);

base.AddWrappedFileDependencies(outputcache_ocpage_aspx.__fileDependencies);

// this is the runtime generated code for initlizing caching
this.InitOutputCache(outputcache_ocpage_aspx.__outputCacheSettings);
base.Request.ValidateInput();
}
=========================


Hope this helps some.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


stcheng

5/29/2006 12:17:00 PM

0

Hello Jason,

How are you doing on this issue or does the info in my last reply helps you
a little? If there is still anything we can help, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)