Saturday, 12 January 2013 13:54

keeping and using application settings in web.config file

Written by 
Rate this item
(0 votes)

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

<add key="SMTP" value=""/>
<add key="AnnouncementEnabled" value="true"/>

later you can use those settings where appropriate.
the following shows how to access those settings
in code behind file of any 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"];
AnnouncementPlaceHolder.Visible = false;

Read 2684 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.