我在一个SqlCacheDependency项目中使用带有轮询的ASP.NET。
有时,我需要禁用SqlCacheDependency,我这样做如下:
<caching>
<sqlCacheDependency enabled="false" pollTime="10000">
<databases>
<!-- ... -->
</databases>
</sqlCacheDependency>
</caching>但是,当我使用SQL依赖项执行HttpRuntime.Cache.Insert()时,这会在我的代码中造成错误。
若要启用SQL缓存依赖项,请在配置文件中的部分中将“启用”属性设置为"true“。
是否有办法以编程方式检查是否启用了此设置?
发布于 2009-09-08 01:42:43
下面的代码对我有效..。
//using System.Web.Configuration;
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("/");
string configPath = "system.web/caching/sqlCacheDependency";
SqlCacheDependencySection section = (SqlCacheDependencySection)webConfig.GetSection(configPath);
bool enabled = section.Enabled;https://stackoverflow.com/questions/1387387
复制相似问题