Thursday, May 31, 2007

Site Monitoring - Simple Tool

You want to ensure that your site is accessible 24x7, and want to be notified ASAP if there is an outtage. Here is a simple recipe.
  1. Create a "KeepAlive" page; a simple page with a static, predictable response. I have created a simple page that displays the Site Name, Web Server Name, and Site IP Address:
  2. Implement a VBScript which makes an http request of the Keep Alive page, returning the response string. The script implements the Microsoft.XMLHTTP object. If the request does not resolve or returns an unexpected result, the script sends an email to the stakeholder (you).
  3. Implement an NT Scheduled Task to run the VBScript (#2) every five minutes. Hopefully, you'll never hear from the tool :)

Tuesday, May 29, 2007

ASPBufferingLimit - IIS5 vs. IIS6

On upgrading a web server from Win2K/IIS5 to Win2K3/IIS6, an old classic ASP application stopped working. This app pulled a large recordset from a SQL database, dumped the records into a large array, and then looped through the array, rendering a grid. I'm not sure why it needed the intermediate step, but of course the developer was long gone from the company. Such is life. Here's the error encountered:


First I ruled out the most obvious and usual offenders during a migration - code and data. Configuring the app on my development machine (IIS5), pulling down the production code and pointing to the production db, the app functioned swimmingly.

Moving on, I researched and came across an IIS ADSI property, "ASPBufferingLimit". Apparently IIS6 sets a lower constraint on the ASP Buffer than IIS5. Good for a healthy web server, but bad for some legacy apps.

The issue was resolved by upping the buffer limit on the IIS6 server. The server administrator accomplished this by running:

    c:\inetpub\adminscripts\adsutil.vbs set w3svc/aspbufferinglimit value
Note: The default setting in IIS6 is ~4MB. The default setting in IIS5 is not visible, apparently, but is rumored to be ~128MB. That seems high to me but I have no choice other than to trust google research :)

Friday, May 25, 2007

Enable IIS 6.0 Extensions using VBScript

If you've worked with IIS 5 and IIS 6, you know that IIS 6 has some tighter default security settings. For example, an administrator must take explicit steps to enable the server execution of ASP/ASP.NET applications. This is accomplished with a few quick clicks, but I'm always looking for shortcuts, e.g.

    Set IIsWebServiceObj = GetObject("IIS://localhost/W3SVC")IIsWebServiceObj.EnableWebServiceExtension "ASP.NET v1.1.4322" IIsWebServiceObj.SetInfo
Taking it a step further, suppose you have a proprietary extension, for instance a dll or exe which serves as an engine to render dynamic html. In other words, say you have a very OLD application. Here's how you would handle that wrinkle:

    Option explicit
    dim IIsWebServiceObj

    Set IIsWebServiceObj = GetObject("IIS://localhost/W3SVC")

    'Enable Proprietary Extention
    IISWebServiceObj.AddExtensionFile "c:\mydll.dll", true, "MyDLL", true, _ "MyProprietaryExtensions"
    IIsWebServiceObj.SetInfo

    wscript.echo "success!"

Wednesday, May 23, 2007

"Visual studio could not identify the version of ASP.NET on the Web server. Do you want to continue?"

I happened upon this warning today when attempting to execute a Project\Copy Project for my web application in VS.NET 2003.


    (Copy Project Interface; Options I chose to create a lean deployment directory...)
    (...And the mysterious warning)

Browsing Google and various Forums, I was led to believe that my .NET Framework/ASP.NET installs were somehow corrupt, and I would have to reinstall or run the aspnet_regiis.exe utility. This didn't sound right to me. I have functioning 1.1/2.0 apps in my development environment, and was able to execute the Copy Project for other 1.1 projects.

I beat myself up about this a bit, and then finally selected "Yes". VS.NET went ahead and built the deployment directory as specified, but not before presenting me with the following popup:

This prompt was familiar to me; it's what you see when an application does not have anonymous access enabled in IIS. Enabling anonymous access eliminated the original VS.NET error!

Hopefully this tip will save someone troubleshooting time or scalp hair.

Monday, May 21, 2007

Overriding Web.config Using Location Tag

Let's say you have a web application with several static configuration settings stored in the <appsettings> collection. Then let's say you want one module of your application to behave differently, i.e. a different set of Application Settings should apply.

Use the <location> tag in web.config to describe the settings for folders within the application.

Web.config Snippet
I have a web application set up in c:\inetpub\myapp, aka http://localhost/myapp. A snippet from web.config is illustrated here:

The application reads settings from the collection by default, unless the request is made to the Test folder.


MyApp Settings

The following screen shot illustrates the default behavior:



Test Settings

And here are the overrides, using the same test page under the /Test folder:
Piece of cake, huh? For the brief testconfig.aspx source code, visit the following link.

Friday, May 18, 2007

Developers: Friendly HTTP Errors can be Unfriendly


Be sure to disable friendly http errors when developing web applications.


These "friendly" errors can mask a problem when troubleshooting. This is prevalent in ASP applications. The following app is missing a virtual directory, and the client has friendly errors turned on:

That doesn't really tell you much, does it? Now here's what we get with the option turned off:

That's a little more informative (minus the proprietary details), isn't it? Keep it unfriendly!

Wednesday, May 16, 2007

Get To Know Your Hosts File

What is the Hosts File
It is a plain text file located within your system directory. It has no file extension.

  1. Windows 2000 - c:\winnt\system32\drivers\etc\hosts
  2. Windows XP, 2003 - c:\windows\system32\drivers\etc\hosts
  3. You'll find equivalent files in other OS's (e.g. Unix)
What Does it Do?
Your Hosts file overrides DNS, forcing HTTP requests to route the way you specify.

Why is it Useful?
There are all kinds of uses for Hosts, depending on your problem at hand. Here are some examples:

  1. You set up numerous IIS sites (e.g. http://mysite.com) in a development environment (server OS), and want to test them via a browswer.
  2. You are developing a single site with multiple behaviors based on domain name (e.g. http://myBlueSite.com has a blue background; http://myRedSite.com has a red background). You want to be able to test these behaviors.
  3. Your are troubleshooting your company's load-balanced server farm. Customers are complaining about a site/application, but you are having difficulty recreating. If the problem is isolated to a specific server, you can force http requests to each server in the farm, provided you have the list of IP addresses.
  4. You want to block various ad/banner nuisances.
Brief Example
You are developing a fictional site to IIS, running Windows XP. Call this site http://diablolovessteak.com.
  1. Open c:\windows\system32\drivers\etc\hosts in a text editor
  2. Add the following line:
  3. 127.0.0.1 diablolovessteak.com
  4. Save the file.
  5. Close any open internet browsers.
  6. Open a browser and go to http://diablolovessteak.com

The request will open the home page of your default web site. If you've never used Hosts, give it a shot!

Monday, May 14, 2007

DNS For Dummies

If you are like me, application-heavy and network-light, then DNS is a relative mystery to you. A friend (network guy) gave me the following high level explanation.

You type and enter an address into your browser, e.g. http://diablopup.blogspot.com.



The first thing that happens is your computer asks your ISP's (e.g. AT&T's) DNS server (1) "do you know the IP address for this website?" If it does, it will tell your computer what it is, and you connect directly to the Website Server (3).

If your ISP's DNS server doesn't know, it will ask (in a roundabout way) the website owner’s DNS server for the IP address(2). Then it connects to the website server (3).

Once your ISP's DNS server knows the IP address, it keeps it in cache so it doesn't have to ask again, thereby making the connection quicker on subsequent requests. This is why you sometimes experience a slow page load when visiting a website for the first time, but then witness quicker connection on subsequent visits.

There are more "nuts and bolts" to DNS, but this is an intuitive picture for people who can't work with DNS directly.

Thursday, May 3, 2007

Installing a Windows Service

Background

A few weeks ago I wrote a brief entry on Lewis Moten's Visual SourceSafe Journal Monitor. This tool runs as a windows service, polling the specified journal.txt every few minutes and updating a data source with the latest VSS changes.

This got me interested in windows services in general and how you set them up using VS.NET. Here is a link to another CodeProject article focusing on setting up a Windows Service project. It details:

  1. How to set up and build a simple Windows Service project.
  2. How to create a setup package (.msi) to install the Windows service.

I work for an organization where the administrators will not accept an .msi package. They want more visibility into what exactly you are trying to do to their production machines, since they are ultimately responsible for keeping them up and running.

Here's how you can install/uninstall a windows service .exe using VBScript .