Thursday, 16 April 2009

Strange mod_mono behaviour with similar path names

We saw some very strange behaviour the other day when testing an ASP.NET Web Service under mod_mono and Apache.

The application we were testing stores some configuration information in a file that’s in the root application directory. As part of the testing we wanted to setup two instances of the application with different configurations, so we copied the contents of the directory from /srv/www/htdocs/ShoutAlarmService to /srv/www/htdocs/ShoutAlarmService2 but changed the contents of the configuration file in the copy. We’re using AutoHosting on the server so the application was automatically available at the appropriate URLs: http://localhost/ShoutAlarmService/Service1.asmx and http://localhost/ShoutAlarmService2/Service1.asmx.

The strange thing was that when we went to /ShoutAlarmService2/ it was actually using the ShoutAlarmService configuration file. Further investigation seemed to show that mono was actually serving the files in the ShoutAlarmService directory rather than the copy- we renamed one of the files in the copy, but it was still found ok! We also created an HTMLPage1.aspx file in each directory, but had them printing out different messages. Regardless of the URL you went to you got the same result. However, if you did the same thing with a .htm file then you got the different files. This suggested something wrong with Mono rather than some strange Apache configuration. In the end to get it working we just renamed the copy to BlahAlarmService.

I wanted a bit of a better explanation though, so today I did some more experimentation and found that if you just copy the directories as described above you get the problem. However, if you copy the directory and then restart apache a couple of times it all works correctly. Copying to a directory called BlahAlarmService seems to work without any issues.

My guess is that there’s a funny in the AutoHosting implementation and the way it maps virtual and physical application directories. But working out the exact problem isn’t my top priority at the moment!

Wednesday, 15 April 2009

ASP.NET Web Site Paths

Finding out your web application’s path seems to cause a little confusion.

A good place to start is this MSDN article. The HttpRequest object that contains all these paths is available via the HttpApplication, HttpContext, Page, and UserControl classes.

For example, to get the physical location of the Web Application you could do the following:

HttpRequest request = HttpContext.Current.Request;
string applicationRoot = request.PhysicalApplicationPath;

If you need to extract a particular part of a path, then you probably want to use the System.IO.Path member functions.

Monday, 6 April 2009

GPS and HTC Touch HD

I've got an HTC Touch HD and use it to listen to music while running (good phone by the way). I thought it would be good to use the built-in GPS to log my route and load the results up to MapMyRun or Google Maps, so I went on the hunt for some free software that I could try.

A little searching later and I found WMMiniGPS. It logs your position at a configurable time interval and allows you to export it to KML or GPX format. Google Maps accepts KML and MapMyRun takes GPX so it seems to fit the bill!

I gave it a try this weekend and it did the job fine. The only issue I had was leaving it running in the background seemed to cause Windows Media Player to stutter a little sometimes.

Once I'd uploaded the results, both MapMyRun and Google Maps showed the route and distance travelled. I was hoping that MapMyRun could use the plotted points to work out my speed over various sections, and record my total time. But apparently it doesn't have that functionality.