Home > ASP.NET 2.0, C# > Get data from web.config

Get data from web.config

Thursday, 24 April, 2008 Leave a comment Go to comments

Any data
——————————————————
store:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="admins" value="esetov_b, lobanov_v"/>
</appSettings>
...

get:
string admins = ConfigurationManager.AppSettings["Admins"];

Connection String
——————————————————
store
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ASPGConnectionString" connectionString="Data Source=DS;Initial Catalog=basename;Persist Security Info=True;User ID=user;Password=psw"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
...

get
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);

Advertisements
  1. baurdotnet
    Friday, 23 May, 2008 at 10:31 am

    using sample:
    void AdminMode(string currentuser)
    {
    string admins = ConfigurationManager.AppSettings["Admins"];
    admins = admins.ToUpper();
    currentuser = currentuser.ToUpper();
    int index = admins.IndexOf(@currentuser);
    if (index != -1)
    {
    //admin settings
    } else
    {
    //usersettings
    };
    }

  2. Soubhik
    Saturday, 6 August, 2011 at 6:26 am

    It’s helpful.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: