Storing info in Web.config

Posted on 2006-05-31
Last Modified: 2006-11-18
I have a handful of methods spread across a handful of pages that act differently depending on whether or not the contents of a Session var are in one of two possible groups:

if idDept = Active

I'd like to store an array of active deparments in Web.config so that any method needing that info looks to that array.

How would i create that key in .config and how would code access that the array?
Question by:juststeve
    LVL 20

    Expert Comment

    Could you not use a class?>
    LVL 5

    Accepted Solution

    To create a key in web.config use,
        <add key="dept" value="Test1" />

    To read the values use,

    However, in your case you need to read a list of department. It achieve it, you could store a delimiter(like ',' or ';') set of values and then you could use the split method to split it into an array.

    Using a configuration section handler and list of values would be more useful.

    LVL 5

    Expert Comment


    Author Comment

    Probably...but to my way to thinking it seems easiest/cleanest to not create a new entity for something like this. I save my db's connection strings there making that string availiable to all page via a simple:

            Dim connStr As String = ConfigurationSettings.AppSettings("connStr")

    So that would seem to be half my answer...create a key/value pair in  <appSettings>:

       <add key="idDept"      value="1,5,6,9,14"/>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now