认识ASP.NET配置文件Web.config(2)

2008-02-22 09:30:05来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

  二是在 <configSections> 区域之后为声明的节做实际的配置设置。

  示例:创建一个节存储数据库连接字符串

<configuration>
 <configSections>
 <section name="appSettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>

 <appSettings>
  <add key="scon" value="server=a;database=northwind;uid=sa;pwd=123"/>
 </appSettings>

 <system.web>
  ......
 </system.web>
</configuration>

  四、访问Web.config文件

  你可以通过使用ConfigurationSettings.AppSettings 静态字符串集合来访问 Web.config 文件示例:获取上面例子中建立的连接字符串。

Dim sconstr As String = ConfigurationSettings.AppSettings("SconStr")
Dim scon = New SqlConnection(sconstr)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:用asp.net还原与恢复sqlserver数据库

下一篇:用ASP/ASP.NET实现网络空间管理