.NET 2.0 Configuration配置文件的保存问题



Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
TestSection section 
= config.Sections["Test"as TestSection;
section.UserName 
= "Vivi";
// 在Vistual Studio调试时,config.FilePth是“AppName.vshost.exe.config”;
// 正常运行程序(不是在Visual Studio中按F5启动)时,config.FilePth才是“AppName.exe.config”。
// 所以,这两种不同情况下config.Save();保存到了不同的文件中。
config.Save();            
config.SaveAs(
"myconfig.xml");
// 执行完上面的语句“config.SaveAs("myconfig.xml");”后,config.FilePth变成了“myconfig.xml”,
// 所以下面的config.Save()仍然是保存配置到myconfig.xml,而不是AppName.exe.config。
config.Save();



from:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_aspnetconfig/html/c282a0c3-0642-458b-8426-565ead922749.htm
 




Scope of Configuration Settings


   

Configuration level

File name

File description

Server

Machine.config

The Machine.config file contains the ASP.NET schema for all of the Web applications on the server. This file is at the top of the configuration merge hierarchy.

Root Web

Web.config

The Web.config file for the server is stored in the same directory as the Machine.config file and contains default values for most of the system.web configuration sections. At run time, this file is merged second from the top in the configuration hierarchy.

Web site

Web.config

The Web.config file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site.

ASP.NET application root directory

Web.config

The Web.config file for a specific ASP.NET application is located in the root directory of the application and contains settings that apply to the Web application and inherit downward through all of the subdirectories in its branch.

ASP.NET application
subdirectory

Web.config

The Web.config file for an application subdirectory contains settings that apply to this subdirectory and inherit downward through all of the subdirectories in its branch.

Client application
directory

ApplicationName.config

The ApplicationName.config file contains settings for a Windows client application (not a Web application).



Configuration Structure


ASP.NET configuration files are called Web.config files, and they can appear in multiple directories in ASP.NET applications. The ASP.NET configuration hierarchy has the following characteristics:

posted @ 2008-06-02 16:25  h2appy  阅读(412)  评论(0编辑  收藏  举报