【问题标题】:Grab duration of outputcacheprofile programmatically in .NET在 .NET 中以编程方式获取 outputcacheprofile 的持续时间
【发布时间】:2018-09-20 18:57:56
【问题描述】:

在 ASP.NET 中有没有办法以编程方式获取 outputcacheprofile 的 duration?

<outputCacheProfiles>
          <add name="Documents" duration="600" enabled="false" varyByParam="*" />

【问题讨论】:

    标签: c# asp.net .net web-config outputcache


    【解决方案1】:
    private int GetSetting()
    {
        // Get the Web application configuration.
        System.Configuration.Configuration webConfig =
            WebConfigurationManager.OpenWebConfiguration("~/");
    
        // Get the section.
        string configPath = "system.web/caching/outputCacheSettings";
        System.Web.Configuration.OutputCacheSettingsSection outputCacheSettings =
            (System.Web.Configuration.OutputCacheSettingsSection)webConfig.GetSection(
                configPath);
    
        // Get the profile at zero index.
        System.Web.Configuration.OutputCacheProfile outputCacheProfile =
            outputCacheSettings.OutputCacheProfiles[0];
    
        return outputCacheProfile.Duration;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 2019-04-30
      • 2011-07-09
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多