Configuration 检索<;缓存>;来自web.config的元素

Configuration 检索<;缓存>;来自web.config的元素,configuration,web-config,configurationmanager,Configuration,Web Config,Configurationmanager,我一直在尝试从web.config获取缓存元素,但迄今为止失败了 使用此代码时: Configuration conf = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath); 我能够获取web.configh文件。 当我使用 conf.GetSection("system.web/membership"); 我成功地获得了会员资

我一直在尝试从web.config获取缓存元素,但迄今为止失败了

使用此代码时:

Configuration conf  = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
我能够获取web.configh文件。 当我使用

conf.GetSection("system.web/membership");
我成功地获得了会员资格

当我使用

conf.GetSection("system.web/caching");
我得到空值

有什么想法吗

下面是web.config的一部分:

    <system.web>
<caching>
  <sqlCacheDependency enabled="true" pollTime="1000">
    <databases>
      <clear />
      <add name="Tests" pollTime="1000" connectionStringName="TestsConnectionString"/>          
    </databases>        
  </sqlCacheDependency>      
</caching>
        <authentication mode="Forms">
        <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    </authentication>
    <membership>
        <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
        </providers>
    </membership>


..

您是否已将返回类型正确转换为OutputCacheSection

const string outputCacheKey = "system.web/caching/outputCache";
var outputCacheSection = ConfigurationManager.GetSection(outputCacheKey) as OutputCacheSection;
现在假设您想要在第一个提供者节点中获得一个名为connectionString的属性,例如

<caching>
  <outputCache enableOutputCache="true" defaultProvider="MyRedisOutputCache">
    <providers>
      <add name="MyRedisOutputCache" connectionString="myapp.redis.cache.windows.net:6380,password=hellopassword,ssl=True,abortConnect=False" type="Microsoft.Web.Redis.RedisOutputCacheProvider,Microsoft.Web.RedisOutputCacheProvider" />
    </providers>
  </outputCache>
</caching>

您是否已将返回类型正确转换为OutputCacheSection

const string outputCacheKey = "system.web/caching/outputCache";
var outputCacheSection = ConfigurationManager.GetSection(outputCacheKey) as OutputCacheSection;
现在假设您想要在第一个提供者节点中获得一个名为connectionString的属性,例如

<caching>
  <outputCache enableOutputCache="true" defaultProvider="MyRedisOutputCache">
    <providers>
      <add name="MyRedisOutputCache" connectionString="myapp.redis.cache.windows.net:6380,password=hellopassword,ssl=True,abortConnect=False" type="Microsoft.Web.Redis.RedisOutputCacheProvider,Microsoft.Web.RedisOutputCacheProvider" />
    </providers>
  </outputCache>
</caching>

看看这个问题和第一个答案:谢谢!这正是我需要的!(现在,如果我能找出如何将你的评论标记为答案…)看看这个问题和第一个答案:谢谢!这正是我需要的!(现在,如果我能找出如何将你的评论标记为答案…)