MC+A Stream

Our Blog and News Stream

Changing Appsettings in the Web.Config

October 18th, 2007

Sometimes when creating a new application that will be deployed in multiple locations, it’s necessary to have some globally configurable variables in the web.config file. It’s important to give the users as easy of an experience in installing the application as possible.

We aim to make all of our applications easy to install, configure and use. This following code is the event when the user clicks on the button to change the appSettings in the web.config file.

using System.Web.Configuration;

protected void SettingButton_Click(object sender, EventArgs e)
{
Configuration config;

config = WebConfigurationManager.OpenWebConfiguration(“~”);

AppSettingsSection settingChange;

settingChange = config.GetSection(“appSettings”) as AppSettingsSection;

if (settingChange != null)
{

settingChange.Settings["setting"].Value = setting.Text;

config.Save();

}

}

As you can see, you first need to define what configuration file that you wish to change. In the above example, the first 2 lines of code open the web.config file for the local application. If you wish to configure a different file, change “~” to “folder\config.config” (depending on the location of the file).

The next 2 lines define the AppSettingsSection and in the above example, we are changing values of keys located in the appSettings section. To conclude the event, check if the value entered is null and if it is not, write the new value to the web.config file.

Once IIS realizes that the web.config file has been changed, it should then reset the application and begin to use the new values during runtime.

That’s it! If the web.config file is not updating, check to see if it is read-only or that the username your application is running under has the proper permissions to write to the web.config file.

New Office (Loft)

August 9th, 2007

What a week it has been for MC + A. We recently relocated our place of business from downtown Chicago to some new digs close to Wrigley Field. Being a life-long Cubs fan, it feels good to be able to come to this area of the city a few days a week. My Cubbies may have lost 4 in a row, but this looks to be the start of a good streak for MC + A.

Hopefully, the arrangement that we have in our new office with one of our partners will turn out to be fruitful for both parties involved. We have been working together for awhile and the opportunity for more face to face collaboration certainly can’t hurt either of us. Meeting people that I personally have been working with for months now is great. No one ever looks like you think they do when you talk to them over the phone or on instant message. The other nice thing about working with your partners in a shared space is that you know for sure that they are not just sitting at home in their skivvies while you are talking to them. Get that image out of your head now. :)

Any of you who are reading this post have more than likely moved an office from one point to another or started a new job with new people. Hopefully, my new office mates don’t drive me crazy or force me to a life of boozing in order to be able to cope with my new surroundings.

Page 2 of 212