Click here to Skip to main content
6,636,867 members and growing! (19,013 online)
Email Password   helpLost your password?
Development Lifecycle » Design and Architecture » General     Advanced License: The Code Project Open License (CPOL)

Application Block - ASP.NET Website Maintenance

By Anton Pious Alfred

ASP.NET Website would eventually be deployed on the production server. As the application grows so too the number of web pages. Invariably bugs or crashes occur. After deployment there should be ways to gracefully maintain this website.
C# 2.0, Windows, .NET 2.0, ASP.NET, WebForms, VS2005, Architect, Dev
Posted:13 Aug 2007
Views:15,666
Bookmarked:17 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
3 votes for this article.
Popularity: 1.84 Rating: 3.86 out of 5
1 vote, 33.3%
1

2

3
1 vote, 33.3%
4
1 vote, 33.3%
5
Comat WebSite Watcher

Introduction

ASP.NET Website would eventually be deployed on the production server. The deployment has been fine tuned to deploy a single page with single page assembly which has already been incorporated since VS 2005. As the application grows so too the number of web pages. Invariably bugs or crashes occur. After deployment there should be ways to gracefully maintain this website.

Background

While there are other crude ways to maintain an ASP.NET website I felt this needs to be more structured. Considering that ASP.NET website can span serveral modules with hundreds of pages the level of control regarding maintainance should be configurable. Wouldn't it be better if we are able to have control even to the page level?

This article addresses this issue and is primarily meant for architects, technical leads and configuration managers who care for graceful maintenance of the Web application.

This article uses HttpModule to perform this task along with custom web.config configuration settings.

Using the code

This has to be used only on Live (Production) or Quality Assurance (Testing) Environment and never on a Development Environment. Can be easily plugged into an existing application by copying the assemblies Comat.WebSiteWatcher.Business.dll and Comat.WebSiteWatcher.Config.dll present in attached binary to the bin folder of the web application and make configurable changes to the web.config file.

Website Watcher Module

This is a HttpModule which is loaded to the HttpModule collection of HttpApplication as depicted in the figure above. This needs to be loaded before redirecting modules like FormsAuthentication etc. We use a HttpModule to prevent unwanted page request processing.

If no redirecting modules present. Add the Module as follows.

<httpModules>

    <add type="Comat.WebSiteWatcher.Business.WebSiteWatcherModule, Comat.WebSiteWatcher.Business" name="WebsiteWatcher" />

</httpModules>

If redirecting modules like FormsAuthentication is used you need to do a work around. I wish the ASP.NET team can come up with an add module at a particular position than at the end.

<httpModules>

    <remove name="FormsAuthentication" />
    <remove name="UrlAuthorization" />

    <add type="Comat.WebSiteWatcher.Business.WebSiteWatcherModule, Comat.WebSiteWatcher.Business" name="WebsiteWatcher" />

    <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
    <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />

</httpModules>
Configuration Settings

Now that the module is loaded we need to provide the configuration settings for it in the web.config file.

<comat.webSiteWatcher isUsed="true">
    <webSite isBlocked="false" redirectUrl="~/Maintenance/WebsiteDown.aspx">
        <blockFolders redirectUrl="~/Maintenance/ModuleDown.aspx">
            <!-- block all folders which have this folder combination -->
            <blockFolder>/BlockedFolder/SubFolder/</blockFolder>
            <!-- block only this particular folder -->
            <blockFolder>http://localhost/Security2005/BillManager/</blockFolder>
        </blockFolders>
        <blockPages redirectUrl="~/Maintenance/PageDown.aspx">
            <!-- block all pages in any folder with name Customer.aspx -->
            <blockPage>Customer.aspx</blockPage>
            <!-- block only this particular page -->
            <blockPage>http://localhost/Security2005/Default.aspx</blockPage>
        </blockPages>
    </webSite>
</comat.webSiteWatcher>

The settings are self explanatory. One has control over whether.

  1. to use this HttpModule
  2. to bring down the entire website
  3. to bring down a module(s) or folder(s)
  4. to bring down a web page(s)
The values can either be relative or absolute depending on your need. Example specifying Customer.aspx would block all pages in all folders with Customer.aspx.Tilde ~ paths are not supported. If you want absolute path specify the full path like http://localhost/Security2005/Default.aspx . The same holds for the folder. High level switches are given for the WebSite so that you can quickly turn it on in case of a major crash or opt not to use the HttpMododule when not in maintenance mode.

Now that we have specified these settings we need to be able to read it. To do this we create our own custom <configSections> node. We need to add this to the top of the <configuration> settings in web.config file.

<configSections>
    <section name="comat.webSiteWatcher"
      type="Comat.WebSiteWatcher.Config.ModuleConfig,Comat.WebSiteWatcher.Config" />
</configSections>
Maintenance Pages

The redirectUrl attribute points to pages which display a custom maintenance message like Website, Module or Page is down for maintenance. This needs to be placed in a separate folder and security restriction removed so requests can be redirected to these pages. In this example we use forms authentication and we override these settings by having a web.config in this folder with the following settings.

<system.web>
    <authorization>
        <!-- Allow all users -->
        <allow users="*"/>
    </authorization>
</system.web>

Points to note

  • If performance is a major concern. Comment out these three settings in Web.Config when not in maintenance mode.
  • App_Offline.htm is one such file to bring down a Web Site. This is very basic and does not offer any configuration.
  • <location> node in web.config can prevent access to a folder without any configuration setting for user specific messages.
  • This can also be extended to block sensitive folders like the ASP.NET ISAPI filter does for App_Code, App_Data etc folders. Here one can customized which folder is sensitive and provide a custom message than the default page not found.

History

13 Aug 2007 : Initial Document.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Anton Pious Alfred


Member
Solution Architect At Comat Technologies.
Occupation: Web Developer
Location: India India

Other popular Design and Architecture articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralCool Pinmemberneil_b6:10 6 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Aug 2007
Editor:
Copyright 2007 by Anton Pious Alfred
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project