ASP.NET 以编程方式访问配置节点

本文介绍了如何通过编程方式访问ASP.NET配置文件中的关键信息,包括数据库连接字符串和身份验证配置。提供了实例代码来展示如何获取这些配置并使用它们。

1.在web.config文件中有如下配置

 1 <configuration>
 2 
 3     <!--数据库链接配置-->
 4     <connectionStrings>
 5         <add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=QualityCourses;Persist Security Info=True;User ID=sa;Password=sa"
 6             providerName="System.Data.SqlClient" />
 7        
 8     </connectionStrings>
 9 
10     <!--文件上传配置-->
11     <system.web>
12         <identity impersonate="true" userName="January" password="master0932"/>
13       
14     </system.web>
15 
16 </configuration>

 

2.现在在后台代码中获取如上的的配置信息

1 IdentitySection section = (IdentitySection)WebConfigurationManager.GetSection("system.web/identity");
2                     proc.StartInfo.UserName = section.UserName.ToString();
3 string password = section.Password.ToString();

 

详细信息请参看

How to: Access ASP.NET Configuration Settings Programmatically 

转载于:https://www.cnblogs.com/January/archive/2012/05/24/2516743.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值