项目过程中,有时候一些配置信息需要通过配置文件获取,比如web.config之类的文件。
方法如下:
string configPath = "D:/MyProject/trunk/IntOA.Operate.Service/Web.config";
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = configPath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
KeyValueConfigurationElement tmp = appSection.Settings["CorpToken"];那么就取到了节点<appSettings>下的<CorpToken>的信息。
本文介绍了一种从Web.config文件中读取配置信息的方法。通过使用ConfigurationManager和相关类,可以轻松获取如CorpToken等配置项。
741

被折叠的 条评论
为什么被折叠?



