Thursday, April 17, 2008
Posted on Thursday, April 17, 2008 9:48:53 AM (Mountain Daylight Time, UTC-06:00)  Comments [4] | 
Categories: ASP.NET

I was doing some work with a database driven version of the Virtual Earth Tile Service HTTPHandler, and needed to do some debugging. I ran into some odd behavior which took some time to track down, so hopefully this saves someone else some time.

Background

To use a HttpHandler, you need to register it in your web.config. Here's what I had :

<system.web>
      <httpHandlers>
        <add verb="*" path="*.ve" type="DBTileHandler" />
      </httpHandlers>
    </system.web>

This just simply routes requests for anyoldthing.ve to the DBTileHandler class, which must implement IHTTPHandler. Very simple.

Debugging Handlers

Typically I open websites "from file" in Visual Studio as this seems to work a little more consistently with VisualSVN (I think this is some issue with my box, as others on my team have no problems opening via IIS). As a result, when I debug the site, it spins up the ASP.NET Development Webserver (aka "Cassini"), and binds to a random port (e.g 2323). Then the site launches on http://localhost:2323/site. All is well and you can step through your aspx pages.

However, you can't debug http handlers by just starting up the site from Visual Studio. You need to change the Start Action of the project to "Don't open a page. Wait for a request from an external application" as shown below.

asp-start-action

Then once you start the web site, and it builds, you need to use Debug --> Attache to Process, and select aspnet_wp.exe.

attach

At this point you can make requests to your handler, and breakpoints will be hit - curiously you attach to the aspnet_wp.exe process even if you are running the site through Cassini.

So, I was happily debugging my tile handler, and got everything worked out, tile were showing up in my VE Map and all was well in the world. Then I went to try it through IIS. Doh! No tiles!

Firebug showed me that the requests were correct, but they were returning with 404's

firebug

I went back and fired it up in Cassini, and got tiles. IIS - no tiles. Cassini tiles. IIS no tiles.

This was quite odd - why would my handler work in one case and not the other? Clearly there is something different between the web servers but what?

To make a long dull story involving much Googling shorter, the answer is that Cassini automatically maps file extensions specified in the Http Handlers section of the web.config, but IIS requires that the file extension mapping be applied explicitly in IIS. Obviously.

Solution

There are two ways to solve this issue:

1) Add the .ve extension to IIS and map it to the aspnet_isapi.dll

or

2) change the extension in your configuration to a type already handled by ASP.NET - such as ashx or aspx.

I chose the latter because it will simplify the deployment of the site. All I did was tack ".aspx" on the end of the path attribute in my web.config and all was working again.

<system.web>
      <httpHandlers>
        <add verb="*" path="*.ve.aspx" type="DBTileHandler" />
      </httpHandlers>
    </system.web>
Thursday, April 17, 2008 1:46:13 PM (Mountain Daylight Time, UTC-06:00)
I ran through this *exact same process a couple of weeks ago.

Unfortunately with new security restrictions in our organization, I am no longer able to run IIS on a local development machine, so I have to do everything using Cassini. This usually works well, but I've found that I now spend much more time debugging deploy issues than I used to.
Thursday, April 17, 2008 1:47:24 PM (Mountain Daylight Time, UTC-06:00)
By the way, I had to turn off the CoComment widget before I could successfully post a comment.
Thursday, April 17, 2008 2:32:03 PM (Mountain Daylight Time, UTC-06:00)
BTW, you can also set IIS to intercept ALL requests on its port. However, I agree that .ve.ashx or .ve.aspx is an easier deployment. It does make for some ugly urls
Thursday, April 17, 2008 4:26:08 PM (Mountain Daylight Time, UTC-06:00)
ASHX is the default ASP.NET extension for handlers. ASPX is usually for referring to pages. - Not that it really matters since they all use the same ISAPI handler (and the page class is an IHttpHandler as well), but this is the Microsoft convention.
Morten
Comments are closed.