以编程方式在.NET中抓取outputcacheprofile的持续时间

时间:2018-04-11 02:57:10

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

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

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

1 个答案:

答案 0 :(得分:0)

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;
}