检索<缓存>web.config 中的元素缓存>
我一直在尝试从 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>
....
I've been trying to get the caching element from my web.config but have thus far failed.
When using this code:
Configuration conf = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
I am able to get at the web.configh file.
When i use
conf.GetSection("system.web/membership");
I succefuly get the membership section.
When i use
conf.GetSection("system.web/caching");
I get null.
Any ideas ?
part of the web.config below:
<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>
....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已将返回类型正确转换为 OutputCacheSection?
现在假设您想在第一个提供者节点中获取名为 connectionString 的属性,例如
您可以执行以下操作
Have you casted the return type correctly as OutputCacheSection?
Now say you wanted to get an attribute named connectionString within the first provider node e.g.
you could do something like this