在HttpHandler中设置CacheProfile

时间:2009-11-18 12:30:29

标签: asp.net httphandler cacheprofile

在aspx文件中,您可以将CacheProfile设置为Web.Config中定义的特定配置文件。你是如何在HttpHandler中做到这一点的?

我知道您可以使用缓存,但是您可以使用来自Web.Config的缓存配置文件吗?

1 个答案:

答案 0 :(得分:1)

我找到的唯一方法是从配置中读取配置文件并以编程方式应用它:

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...