Link to home
Start Free TrialLog in
Avatar of Vishal Gundage
Vishal Gundage

asked on

How to Add Multiple Username and password In appsettings in app.config?

hello everyone i create one app.config file store in appsettings multiple username and password ?how can i store ? i just see in appsettings key and value and mention also key=username and value=some-pcusername or but i didn't get anything.
                    foreach (var key in appSettings.AllKeys)
                    {
                       //here i want to code with help of storing username and passowrd in appsettings i want to get information of that system
                    }
thank you !
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

In App.config
<configSections>
    <section name="MultiValue1" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <MultiValue1>
    <add key="Key1" value="Value1" />
    <add key="Key2" value="Value2" />
    <add key="Key3" value="Value3" />
  </MultiValue1>

Open in new window

and to read
public static List<string> GetMultiValue(string name)
        {
            List<string> returnValues = new List<string>();

            try
            {
                NameValueCollection rules = ConfigurationManager.GetSection(name) as NameValueCollection;

                foreach (string ruleName in rules)
                {
                    try
                    {
                        returnValues.Add(rules[ruleName]);
                    }
                    catch
                    {
                        //Rule failed
                    }
                }
            }
            catch (Exception ex)
            {
                //Config failed
            }

            return returnValues;
        }

Open in new window

Avatar of Vishal Gundage
Vishal Gundage

ASKER

Dear Eric This solution i din't understand can u explain in brief i m beginers in .net
The article is meant for beginners. It tells you how you can use the app.config file. Download the demo code, play with it and read the article completely.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.