Storing info in Web.config

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?
Who is Participating?
Sam_JayanderConnect With a Mentor Commented:
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.

Could you not use a class?>
juststeveAuthor Commented:
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"/>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.