现在的位置: 首页 > 综合 > 正文

设计期访问Web.config的代码

2012年09月12日 ⁄ 综合 ⁄ 共 544字 ⁄ 字号 评论关闭

using System.Configuration;
using System.Web.Configuration;
using
System.Web.UI.Design;
//...

IWebApplication webApp = (IWebApplication)Component.Site.GetService(
typeof(IWebApplication) );
Configuration config = webApp.OpenWebConfiguration(true);
ConfigurationSectionGroup systemWeb = config.GetSectionGroup("system.web");
ProfileSection profileSection = (ProfileSection)systemWeb.Sections["profile"];

foreach (ProfilePropertySettings configProperty in profileSection.PropertySettings)
{ // read the settings in each configProperty }

 

config.AppSettings.Settings["maxRetries"].Value

抱歉!评论已关闭.