打开一个非web.config文件作为配置对象 [英] Opening a non web.config file as a configuration object

查看:177
本文介绍了打开一个非web.config文件作为配置对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的情况是,我有一个asp.net MVC项目,我期待将大多数的站点具体设置为一个配置文件,它是不是在Web.config。之所以这样做是为了避免应用程序池回收时,设置改变,但我想保持了很多配置code我已经有了。所以,我一直在试图找出一种方法来加载配置文件作为配置对象,而它是标准的Web.config文件与应用程序加载。我一直在寻找通过一些配置管理器类的加载配置文件,但他们似乎都希望有一个路径,它的类可以找到一台机器,网络或应用程序的配置。那么,有可能加载一个config文件(不是网络,应用程序或设备)作为配置对象?现在看来似乎应该pretty的容易,因为它的一切只是XML,但我似乎失去了一些东西。

So my situation is that I have an asp.net MVC project and I am looking to move most of the site specific settings to a config file that is not the Web.config. The reason for doing so is to avoid the app pool recycling when settings are changed, but I want to keep a lot of the configuration code I already have. So I've been trying to figure out a way to load a configuration file as a configuration object without it being the standard Web.config that loads with the application. I've been looking through some of the Configuration manager classes to load config files, but they all seem to want a path to which the class can find a machine, web, or app config. So is it possible to load a .config file (that is not web, app or machine) as a Configuration object? It seems like it should be pretty easy since its all just XML but I seem to be missing something.

推荐答案

配置更改会导致应用程序域重新启动

Configuration Changes Cause a Restart of the Application Domain

更改Web.config中的配置设置文件间接导致应用程序域重新启动。发生在设计此行为。您可以选择使用configSource属性来引用外部配置文件不会导致重新启动时,一个变化是由。欲了解更多信息,请参阅configSource在一般属性继承节元素。 MSDN

Changes to configuration settings in Web.config files indirectly cause the application domain to restart. This behavior occurs by design. You can optionally use the configSource attribute to reference external configuration files that do not cause a restart when a change is made. For more information, see configSource in General Attributes Inherited by Section Elements. MSDN

在你的web.config:

In your web.config:

<system.net>
   <myconfigSection>
       <myConfigEntry configSource="MyExtraConfig.config" />
   </myconfigSection>
</system.net>

在你MyExtraConfig.config:

In your MyExtraConfig.config:

<?xml version="1.0" encoding="utf-8" ?>
<myConfigEntry>
   <myConfigValue1 a="1" b="2" c="3" />
   <myConfigValue2 d="4" e="5" f="6""/>
</myConfigEntry>

这篇关于打开一个非web.config文件作为配置对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆