Joseph Michael Pesch
VP Programming

Override Application Settings C#

by 31. August 2010 17:18

When you create/edit application settings via the projects properties window in Visual Studio (as shown in screen shot below), it will create app/web.config entries (as shown below in sample .config entry below).  However, if you change those entries in the .config file on a deployed app/web instance, you may notice the updated .config values are not actually being used by the application/web when it runs.  In order to have the application/web use the values from your .config file you can write a custom handler (as shown in the sample code below).

Screen shot of properties dialog:

Sample of .config values entered via the propeties dialog:






  </ MyApplication.Properties.Settings>


Sample of code to override the property:


  <add key="MyackgroundColor"value="white"/>




using System;

using System.Configuration;

using System.Drawing;


publicclass MyUserSettings : ApplicationSettingsBase




  public Color BackgroundColor //Note: property name (i.e. BackgroundColor) is arbitrary




      return ((Color)ConfigurationManager.AppSettings["MyBackgroundColor"]);




      this["BackgroundColor"] = (Color)value;







ASP.Net | C#

Comments are closed