使用编程方式访问系统配置 by zhouwillpower
转自(http://msdn2.microsoft.com/zh-CN/library/4c2kcht0.aspx)
可以从 ASP.NET 应用程序或 .NET 客户端应用程序内部访问运行时配置设置。每个配置节都具有其各自的对象类型,对于 C#,在调用 WebConfigurationManager 类的方法时,需要对这些对象类型进行强制转换。
string configPath = "/MyAppRoot";
// Get the configuration object to access the related Web.config file.
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
// Get the object related to the <identity> section.
IdentitySection section =
(IdentitySection)config.GetSection("system.web/identity");
// Read the <identity> section.
StringBuilder identity = new StringBuilder();
identity.Append("Impersonate: ");
identity.Append(section.Impersonate.ToString());
// Display the <identity> information.
ConfigId.Text = identity.ToString();
posted on 2006-06-24 12:18 zhouwillpower 阅读(186) 评论(0) 收藏 举报
浙公网安备 33010602011771号