How often have you or the users of the application thought you were in development mode of your ASP.NET application but were actually in production? This could be a very costly mistake, especially if someone modifies data. Most companies developing software have multiple application environments such as: Development, Certification "Testing", Demonstration, and Production. It is very critical that developers, quality assurance analysts, users, etc. know what environment they are in. You might think, everyone should know this because they go to a specific URL or it is displayed on the login screen. Guess what, we are all human and often can forget we are in production because there is little variation between the user interfaces in development and production.
This article demonstrates how easy it is to demonstrate the application environment in your ASP.NET applications. By taking advantage of inheritance, each WebForm in the application can derive from a custom base page. This allows the code to be written in one location and reduces redundancy by not coding every page to output the environment. The
BasePage class will render a backsplash image with the application environment repeated as the background. The
BasePage class utilizes a static
AppConfig class to get the
ApplicationEnvironment variable from the Web.config file. The Web.config file contains an
appSetting node. I added a custom
application_environment node to the
application_environment modes in this example are:
- Development - "
- Certification - "
- Demonstration - "
- Production - "
BasePage only renders a backsplash "watermark" image for
DEMO. We do not want to see a backsplash while in production.
As stated above, the code is quite simple. It consists of two classes. The
BasePage class and the
AppConfig class. WebForms that want to display the backsplash inherit from the
This class overrides the
Render method and outputs a backsplash image dependent upon the application environment.
WebForm - Derived Class
This class derives from the
BasePage. It automatically inherits the functionality to render the backsplash image. Any WebForm you want to display the backsplash should derive from
This class is a static class that acts as an interface to the Web.config file. It has properties to retrieve the values from the
appSettings node in the Web.config XML. The Application Environment is stored in the config file.
public class AppConfig
public static AppConfig GetInstance = new AppConfig();
private const string APP_NAME = "application_name";
private const string APPLICATION_ENVIRONMENT = "application_environment";
private Hashtable collection = null;
collection = new Hashtable();
foreach (string key in
catch (Exception e)
throw new Exception("Exception caught " +
"in AppConfig constructor.", e);
public string ApplicationName
public string ApplicationEnvironment
public string GetValue(string key)
catch (Exception e)
throw new Exception("Exception caught" +
" in AppConfig.GetValue", e);
appSettings section that allows custom variables. The application environment is stored here as the
<add key="application_environment" value="CERT"/>
Below is an example of the backsplash seen on the web pages. The application mode is Development -
Another WebForm with an application mode of Development -
Below is an example of the first screenshot but in Certification mode -
That's it! A simple solution to an overlooked problem.