Saturday, 12 January 2013 13:54

keeping and using application settings in web.config file

Written by 
Rate this item
(0 votes)

in asp.net application or website </appSettings>
section in web.config is used to store application
setting to be used.you can keep settings in this
section as -

<appSettings>
<add key="SMTP" value="smtp.gmail.com"/>
<add key="AnnouncementEnabled" value="true"/>
..........
</appSettings>


later you can use those settings where appropriate.
the following shows how to access those settings
in code behind file of any asp.net pages -

first include using System.Configuration; to
use ConfigurationManager class.

//the codes to access settings
string smtpHost;//host for sending emails from .net
smtpHost =ConfigurationManager.AppSettings["SMTP"];
if (Convert.ToBoolean(ConfigurationManager.AppSettings["AnnouncementEnabled"]))
Announcement.Text = ConfigurationManager.AppSettings["Announcement"];
else
AnnouncementPlaceHolder.Visible = false;

Read 2731 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.