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?

User generated image
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

App.config
<configSections>
    <section name="MultiValue1" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <MultiValue1>
    <add key="Credential1" value="abc|123" />
    <add key="Credential2" value="pqr|456" />
  </MultiValue1>

Open in new window

read and split on |
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

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.