Tuesday, July 29, 2008

Managing Your Different Environments Using External Configuration Files

Download Example Solution: Click Here

One thing that I have found as I have worked for my current employer and worked on a large-scale web application is that configuration files can get hairy.  This has proven to be especially true as we have managed the different configurations for our different environments (development, integration, staging and production).

Our web.config files have grown to about 1000 lines, which becomes a bear when you have to make sure that 4 of those files are in sync.

 

External Config Files To The Rescue

Recently I stumbled upon the beauty of external configuration files, which has made me realize that I can isolate the configuration settings that change and only worry about managing those changes in each of the configuration files and not the entire set of configuration settings.

You may put all of your external configuration files in the root folder along with your web.config, but I'm warning you that this can get ugly in a hurry the more environments you have and as the sections of the configuration file you are breaking out.  I recommend making a sub-folder that will hold all of your external config files and reference them by prefixing the configSource with your sub-folder (e.g. configSource="Config\ConnectionStrings.config").  You may then use folders to organize the different types of configuration settings as well.

 

image

 

Keep in mind as you use external config files that you have to have a separate configuration file for each section of the configuration file that you break out.  You also can only specify an external config file at certain levels of the configuration file.  For example, you can't specify an external configuration file for the entire System.ServiceModel section of your config file.  However, you can specify an external config file at the client level under the System.ServiceModel section.

image

Download

Download the example project to see how you might us these external configuration files:

Click Here

Monday, July 28, 2008

When In Doubt, Regen The Proxies

As I've worked with web services, mainly WCF services, I've run into some really funky problems as I've consumed services that have made me want to rip my hair out.  Hopefully this little bit of advice will help many developers keep more of their hair intact.

Update your service reference before getting too far into trying to diagnose the problem:

image

This is often required when a namespace changes in the service code even if none of the method signatures have changed.  This has usually been the case when the service is mysteriously returning null when you know it shouldn't.

Cheers!

Tuesday, July 8, 2008

A Count Down Asp.NET User Control

Download Example Here:

Count Down Test Web Application

Recently at work, I did some work on our website that would alert our users that the website would be going down soon.  The customer wanted "count down" functionality that would give users an idea of how long they have until the site goes down as the time to take the website down approaches.

image

I figured there would be someone who had already done this sort of thing, so I went to Google.  I found an article by Robert Hashemian at http://www.hashemian.com/tools/javascript-countdown.htm that explains how you would create a count down timer with JavaScript.  His example was pretty slick, but I wanted to create a user control in .NET that I could just set the time of when the timer should expire and forget about all the JavaScript under the covers.  So I did just that.

At first I tried to use Mr. Hashemian's way of setting the ending time in the JavaScript and figuring out how much time was left there, but the problem I found was that the time was dependant on the browser's time, so I decided to change the way the initial number of seconds is determined.  Instead of setting the time in JavaScript, I decided to count how many seconds were left until the target time and just set the number of seconds in JavaScript, so the functionality wouldn't be disrupted by time zone differences.

Anyway, after some work, all I had to do was put the user control tag in my page and set the time in the code behind like so:


            this.countDown1.TimeToEnd = DateTime.Now.AddHours(1.02);

            this.countDown2.TimeToEnd = new DateTime(2050, 1, 1);

I've created a sample web app that uses this control shown in the examples above.

Download Here:

Count Down Test Web Application