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?
juststeveAsked:
Who is Participating?
 
Sam_JayanderConnect With a Mentor Commented:
Hi,
To create a key in web.config use,
  <appSettings>
    <add key="dept" value="Test1" />
  </appSettings>

To read the values use,
  ConfigurationSettings.AppSettings("dept")

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.

HTH,
--Sam.
0
 
REA_ANDREWCommented:
Could you not use a class?>
0
 
Sam_JayanderCommented:
0
 
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"/>
0
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.