简体   繁体   English

.Net中的App.Config和Web.Config有什么区别?

[英]What is the difference between App.Config and Web.Config in .Net?

我在.net应用程序中看过这个Appconfig和Webconfig,但我不知道两者之间有什么区别。

The choice of the configuration file name is determined by the hosting environment you choose for the service. 配置文件名的选择取决于您为服务选择的托管环境。 If you are using IIS to host your service, use a Web.config file. 如果您使用IIS来托管服务,请使用Web.config文件。 If you are using any other hosting environment, use an App.config file. 如果您使用的是任何其他托管环境,请使用App.config文件。

In Visual Studio, the file named App.config is used to create the final configuration file. 在Visual Studio中,名为App.config的文件用于创建最终配置文件。 The final name actually used for the configuration depends on the assembly name. 实际用于配置的最终名称取决于程序集名称。 For example, an assembly named "Cohowinery.exe" has a final configuration file name of "Cohowinery.exe.config". 例如,名为“Cohowinery.exe”的程序集的最终配置文件名为“Cohowinery.exe.config”。 However, you only need to modify the App.config file. 但是,您只需要修改App.config文件。 Changes made to that file are automatically made to the final application configuration file at compile time. 在编译时,对该文件所做的更改将自动发送到最终的应用程序配置文件。

In using an App.config, file the configuration system merges the App.config file with content of the Machine.config file when the application starts and the configuration is applied. 在使用App.config文件时,配置系统会在应用程序启动并应用配置时将App.config文件与Machine.config文件的内容合并。 This mechanism allows machine-wide settings to be defined in the Machine.config file. 此机制允许在Machine.config文件中定义机器范围的设置。 The App.config file can be used to override the settings of the Machine.config file; App.config文件可用于覆盖Machine.config文件的设置; you can also lock in the settings in Machine.config file so that they get used. 您还可以锁定Machine.config文件中的设置,以便它们得到使用。 In the Web.config case, the configuration system merges the Web.config files in all directories leading up to the application directory into the configuration that gets applied. 在Web.config情况下,配置系统将导致应用程序目录的所有目录中的Web.config文件合并到应用的配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM