ASP.NET的web.config:configSource对文件属性 [英] ASP.NET web.config: configSource vs. file attributes
问题描述
在一个的web.config
- 文件在ASP.NET应用程序配置的某些部分,如的appSettings
和是connectionStrings
,支持的属性 文件
和 configSource
什么是使用 文件之间
-attribute和 configSource $ C $的区别C>
-attribute?当你应该使用哪个属性,并可以同时使用?
<?XML版本=1.0&GT?;
<结构>
<文件的appSettings =AppSettings.config>
< /的appSettings>
<是connectionStrings configSource =ConnectionStrings.config>
< /&是connectionStrings GT;
<! - ... - >
< /结构>
文件
属性
- 指定包含自定义应用程序配置设置的外部文件的相对路径
- 针对于
的appSettings
部分 - 将合并(和覆盖)的config文件设置
- 不会导致Web应用程序重新启动
- http://msdn.microsoft.com/en-US/library/ms228154(v=vs.100).aspx
- 使用Configuration.AppSettings.Settings.添加 API将导致所有的设置被合并到主
的.config
在<一个href=\"http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx\">Configuration.保存电话。 - 因为.NET 1.1
修改指定的文件时,
configSource
属性
- 可以申请到配置文件的大部分路段,而不仅仅是
的appSettings
- 将覆盖在整个栏目与外部文件,否合并
- CAN导致Web应用程序重新启动
- http://msdn.microsoft.com/en-US/library/system.configuration.sectioninformation.configsource(v=vs.100).aspx
- 使用Configuration.AppSettings.Settings.添加 API将导致所有的设置被添加到
configSource <指定的文件/ code>在<一个href=\"http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx\">Configuration.保存电话。
- 因为.NET 2.0
的文件
属性指定包含自定义设置,如您在web.config文件的appSettings进入做一个外部文件。
同时,在 configSource指定的外部文件
属性包含您声明configSource的部分中的设置。例如,如果您使用的网页部分的configSource属性,则外部文件将包含的页面部分中的设置。
在specifified外部配置声明的自定义设置
文件属性将与的appSettings的设置合并
在web.config文件部分。在此同时,该configSource
不支持合并,这意味着你必须移动整个
部分设置到外部文件。
块引用><一个href=\"http://www.$c$cproject.com/Messages/1463547/Re-difference-between-configSource-and-file-attrib.aspx\">http://www.$c$cproject.com/Messages/1463547/Re-difference-between-configSource-and-file-attrib.aspx
Within an
web.config
-file in an ASP.NET-application some sections of config, likeappSettings
andconnectionStrings
, supports the attributesfile
andconfigSource
.What is the difference between using the
file
-attribute and theconfigSource
-attribute? When should you use which attribute and can you use both?<?xml version="1.0"?> <configuration> <appSettings file="AppSettings.config"> </appSettings> <connectionStrings configSource="ConnectionStrings.config"> </connectionStrings> <!-- ... --> </configuration>
解决方案
file
attribute
- Specifies a relative path to an external file that contains custom application configuration settings
- specific to the
appSettings
section- will merge (and override) settings in the .config file
- will not cause web application to restart when modifying the specified file
- http://msdn.microsoft.com/en-US/library/ms228154(v=vs.100).aspx
- Using the Configuration.AppSettings.Settings.Add API will result in all settings being merged back into the main
.config
on a Configuration.Save call.- since .NET 1.1
configSource
attribute
- can apply to most sections of a configuration file, not just
appSettings
- will override the entire section with the external file, no merging
- CAN cause web application to restart
- http://msdn.microsoft.com/en-US/library/system.configuration.sectioninformation.configsource(v=vs.100).aspx
- Using the Configuration.AppSettings.Settings.Add API will result in all settings being added to the file specified in
configSource
on a Configuration.Save call.- since .NET 2.0
The
file
attribute specifies an external file containing custom settings like you do in the appSettings entry of the web.config file. Meanwhile, the external file specified in theconfigSource
attribute contains the settings for the section which you declare the configSource for. For example, if you use the configSource attribute of the pages section, then the external file will contain the settings for the pages section.The custom settings declared in the external config specifified in the file attribute will be merged with the settings in the appSettings section in the web.config file. In the meanwhile, the configSource does not support merging, it means that you'll have to move the entire section settings into the external file.
http://www.codeproject.com/Messages/1463547/Re-difference-between-configSource-and-file-attrib.aspx
这篇关于ASP.NET的web.config:configSource对文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!