我使用的SqlCacheDependency与ASP.NET项目轮询。

有时候,我需要禁用的SqlCacheDependency,如下其中我做的:

<caching>
  <sqlCacheDependency enabled="false" pollTime="10000">
    <databases>
      <!-- ... -->
    </databases>
  </sqlCacheDependency>
</caching>

然而,这会导致错误在我的代码,当我做一个HttpRuntime.Cache.Insert()与SQL依赖

“启用”选项启用SQL缓存依赖,请将该属性设置为“真”,在配置文件中的部分。

有没有一种方式,如果启用此设置,我可以以编程方式检查?

有帮助吗?

解决方案

下面的代码为我工作...

//using System.Web.Configuration;
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/");
string configPath = "system.web/caching/sqlCacheDependency";
SqlCacheDependencySection section = (SqlCacheDependencySection)webConfig.GetSection(configPath);
bool enabled = section.Enabled;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top