web.config appsetting section in asp.net 2.0

Storing configuration informations has never been so easy like in ASP.Net 2.0.

You can store all your config parameters inside the appSettings section of the web.config file.

Example (Into the web.config file) :
As you can see, you can store every parameter you need for your website.

<configuration/>
    <appSettings>
          <add key="DBHost" value="localhost"/>
          <add key="DBPort" value="3306"/>
          <add key="DBUser" value="root"/>
          <add key="DBPass" value="test"/>
          <add key="DBName" value="mysitedatabase"/>
          <add key="SiteTemplate" value="Default"/>
          <add key="SiteName" value="www.mywebsite.domain"/>
          <add key="EnterpriseName" value="My Enterprise"/>
          <add key="SMTPHost" value="out.myserver.domain"/>
          <add key="SiteEMail" value="info@mywebsite.domain"/>
    </appSettings>
</configuration>

Download this code: webconfig.txt

Now to read configuration parameters from an asp.net page you just need to do this:

dim dbhost as string = System.Configuration.ConfigurationManager.AppSettings(”DBHost”).ToString()
dim DBPort as string = System.Configuration.ConfigurationManager.AppSettings(”DBPort”).ToString()

and so on for all parameters….

It’s a simple task but i hope it will helps…



Comments are closed.