ASP.NET中有没有办法以编程方式获取outputcacheprofile的duration
?
<outputCacheProfiles>
<add name="Documents" duration="600" enabled="false" varyByParam="*" />
答案 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;
}