Setting CacheProfile in HttpHandler
In an aspx file you can set the 开发者_Python百科CacheProfile to a certain profile defined in Web.Config. How do you do this in a HttpHandler?
I know you can use Cache but can you use Cache Profiles from Web.Config?
The only way I have found is to read the profile from the config and apply it programmatically:
var settings = (OutputCacheSettingsSection)
WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings");
var profile = settings.OutputCacheProfiles["ProfileName"];
var cachePolicy = context.Response.Cache;
//Set up your caching here using the profile
cachePolicy.SetExpires(context.Timestamp.AddSeconds(profile.Duration));
//And so on...
精彩评论