cod*_*ing 22 c# asp.net web-config visual-studio
app.config中的appsettings标记具有文件属性:
<appSettings file="other.config">
..
..
</appSettings>
Run Code Online (Sandbox Code Playgroud)
这是如何运作的?它会将appSettings(原始)中的内容与other.config文件合并吗?或者它会覆盖它吗?如果other.config文件不存在,该怎么办呢?
我自己尝试,如果一个键不在原来的,它似乎没有从other.config读取它?
other.config文件应该只有xml节点,还是应该都在appsettings元素中?
<appSettings>
<userId>123</userId>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
要么
<userId>123</userId>
Run Code Online (Sandbox Code Playgroud)
Doc*_*ick 42
这会掩盖一切吗?
关于这个主题的最佳答案之一在这里:ASP.NET web.config: configSource vs. file attribute - 感谢 @Massimiliano Peluso
file属性
appSettings部分.config上的主设置。保存通话。configSource属性
appSettingsconfigSource中指定的文件中。保存通话。System.Configuration.ConfigurationErrorsException如果配置源文件不存在,则抛出该错误。该file属性指定一个包含自定义设置的外部文件,就像您在 web.config 文件的 appSettings 条目中所做的那样。同时,属性中指定的外部文件configSource包含您为其声明 configSource 的部分的设置。例如,如果您使用页面部分的 configSource 属性,则外部文件将包含页面部分的设置。
文件属性中指定的外部配置中声明的自定义设置将与 web.config 文件中 appSettings 部分中的设置合并。同时,configSource不支持合并,这意味着您必须将整个部分设置移动到外部文件中。
http://www.codeproject.com/Messages/1463547/Re-difference- Between-configSource-and-file-attrib.aspx
| 归档时间: |
|
| 查看次数: |
11357 次 |
| 最近记录: |