[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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?
  • 2
1 Solution
Could you not use a class?>
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.

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"/>

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now