【问题标题】:Setting CacheProfile in HttpHandler在 HttpHandler 中设置 CacheProfile
【发布时间】:2009-11-18 12:30:29
【问题描述】:

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

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

【问题讨论】:

    标签: asp.net httphandler cacheprofile


    【解决方案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...
    

    【讨论】:

      猜你喜欢
      • 2011-04-12
      • 2014-03-16
      • 2019-01-02
      • 1970-01-01
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      • 1970-01-01
      相关资源
      最近更新 更多