Ranadheer Reddy
Ranadheer Reddy

Reputation: 4324

retrieve username and password from web.config

I am working with c#.

I have added username and password to web.config like this.

<add key="userName" value="MyName"/>

<add key="userPassword" value="MyPassword"/>

Now i want to retrieve these values. Means am using two text boxes to enter username and password.And code to test them is,

if(textBox1.text=="some code" and textbox2.text=="some code")
{
response.redirect("login.aspx");
}

what should i write in palce of "some code" to retrieve username and password from web.config, so that i can compare them with user entries ?

Thanks.

Upvotes: 0

Views: 3009

Answers (1)

rt2800
rt2800

Reputation: 3045

You can use --> System.Configuration.ConfigurationManager.AppSettings["MyName/MyPassword"]

However, It is risky to place pwd in a config file, why don't you put it into db table and query it before checking?

Upvotes: 1

Related Questions