【发布时间】:2013-11-23 01:55:07
【问题描述】:
如何在 asp.net web.config 文件的 appSetting 路径属性中指定多个相对文件路径。我的 appsetting 密钥位于两个不同的文件中。
<appSettings file="Web.User.config">
</appSettings >
【问题讨论】:
标签: asp.net
如何在 asp.net web.config 文件的 appSetting 路径属性中指定多个相对文件路径。我的 appsetting 密钥位于两个不同的文件中。
<appSettings file="Web.User.config">
</appSettings >
【问题讨论】:
标签: asp.net
您不能为 appSettings 引用多个文件路径。 appSettings 是一个部分,您不能拥有多个部分。但是,您可以添加一个与 appSettings 部分类似的新部分。示例:
<configuration>
<configSections>
<section name="CustomConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
....
<CusTomConfig>
<add key="Key1" value="Value1"/>
</CustomConfig>
然后,您可以通过以下方式访问该部分:
NameValueCollection settings = (NameValueCollection)ConfigurationManager.GetSection("CustomConfig");
第二种选择是使用Custom Configuration Section。这将需要一些样板代码(如 MSDN 文档中所示),但您将能够使用属性访问设置值,而不是使用像 settings["Key1"] 这样的字符串来引用它们。
【讨论】: