Connie DeCinko
Connie DeCinko

Reputation: 191

Where to store .NET application settings

I have a .NET application that needs to reference a global application variable, a number, which is used by the application to allow/disallow users to enter events prior to a date. Currently I have

<appSettings>
    <add key="beginDateRangeDays" value="60" />
    <add key="endDateRangeDays" value="30" />
</appSettings>

in my Web.config. I want the admin users to be able to modify those values periodically via an admin web page. If I allow this, every time they make a change, my app pool will restart.

Where would you recommend storing this? In an external config file? But will that also cause an app pool restart? Should I use a config table in the application's database?

Upvotes: 1

Views: 450

Answers (3)

Bennett Elder
Bennett Elder

Reputation: 95

If you store it in the database then you have control over who accesses it and when. Then you need not worry about making the app pool restart.

Upvotes: 0

Glenn Ferrie
Glenn Ferrie

Reputation: 10390

You should be able to setup application settings, such that they are editable in IIS. See this TechNet article:

http://technet.microsoft.com/en-us/library/cc753062(v=ws.10).aspx

Upvotes: 0

David
David

Reputation: 218827

I want the admin users to be able to modify those values periodically via an admin web page

Database, definitely. The config file is a convenient place to store non-static values, but not always the best place. Step back for a moment and consider two "buckets" of such values:

  1. Logical configurations which users can change within any given instance of the application.
  2. Infrastructure configurations which define any given instance of the application and how it relates to the surrounding environment.

The former is best kept in the application's database, the latter in the config file. The former might contain values like:

  • Business holidays observed this year
  • Values used in calculating business data
  • Defaults for user forms

While the latter might contain values like:

  • Database connection strings
  • URLs for external web services
  • Credentials for service accounts

Let the users change things that they can change without physically breaking the application, and track those changes in the database. Keep the infrastructure details in the config file, since a change to those details would very likely require an app pool restart anyway.

Upvotes: 3

Related Questions