按照下面的配置就可以配置在其它位置了。如果web.config里面有的话就从web.config里面读,没有的话就在site.config里面读。 不用改其它的配置文件。
public static OLConfiguration GetConfig()
{
OLConfiguration config = CacheHelper.Get(CacheKey) as OLConfiguration;
if(config == null)
{
config = (OLConfiguration)ConfigurationManager.GetSection("openlab");
if (config == null)
{
string path;
if (HttpContext.Current != null)
path = HttpContext.Current.Server.MapPath("~/Site.config");
else
path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Site.config";
if (!File.Exists(path))
{
throw new OLException(OLExceptionType.UnknownError, "发生错误: 虚拟目录或网站根目录下没有正确的Site.config文件");
}
XmlDocument doc = new XmlDocument();
doc.Load(path);
config = new OLConfiguration(doc);
CacheHelper.Max(CacheKey, config, new CacheDependency(path));
CacheHelper.ReSetFactor(config.CacheFactor);
}
}
return config;
}