Primarily discussing doing and managing software development - emphasis on .NET and SOA. Other posts about things that are on my mind in true blog style.
Thursday, September 27, 2007
Javascript variance in mouseclick events
Tuesday, September 25, 2007
URL rewriting
In the past I linked to an article on URL rewriting and how to do it. This past weekend I finally modified my personal web site to use URL Rewriting.
I tried a couple different methods of URL Rewriting and finally settled in with http://www.urlrewriting.net as the documentation was good and the implementation fit my needs.
Essentially all that was required was to drop the urlrewriting.dll into my bin directory (adding it as a reference for my website) and adding rewriting rules to my web.config.
The power is in adding rewriting rules to the web.config.
You create the functionality you want as query string variables, and then create a rewriting rule. The rewriting rule defines a regular expression of the "to be" URL and how it maps to the real url.
For example: I am using an imagehandler.ashx file to resize images on the fly. It takes query string parameters:
dir: the subdirectory of my pictures directory to use
file: the picture in that directory to use
width (optional): how wide to make the output picture
height (optional): how tall to make the output picture
This results in a url like this:
http://www.jessandrob.com/imagehandler.ashx?dir=Alberta-Aug-2007&file=DSC00105&width=800&height=600
Which clearly isn't to friendly.
After adding the reference I added this to the web config:
<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites></urlrewritingnet>
<add name="picture_web"
ignorecase="true"
virtualurl="^~/gallery/web/([\d\w\s\-]*)/([\d\w\s\-]*).aspx"
destinationurl="~/ImageHandler.ashx?Path=$1&File=$2.jpg&width=800&height=600"
rewriteurlparameter="ExcludeFromClientQueryString" />
</rewrites>>
After this the url becomes:
http://www.jessandrob.com/gallery/web/Alberta-Aug-2007/DSC00105.aspx
You can see my regular expression is matching digits, letters, whitespace, and dashes for both the directory name and the file name, and they are passed to the query string as "$1" and "$2" per standard Regex notation.
Notice its .aspx instead of .jpg - this seems to be a limitation of IIS. using ".JPG" actually works in the Visual Studio built in web server but fails in IIS - that's something I'll have to look into in the future.
Yes its that simple. I repeated the process for a couple other dynamic pages.
The one thing that did effect me a bit was URL's on the rewritten pages - you'll notice that the rewritten pages are deeper directory wise than the original - this is my design choice. This caused issues on the pages mapping relative urls - specifically I needed to utilize the ASP.NET "~" operator and have the url as runat=server (this was ASP.NET figures out the relative url for me). Where this isn't possible I have to manage the urls a bit more manually.
Trouble from Windows Live Writer?
I had some problems posting to my company blog from Windows Live Writer today.
It looks like in the past update of Live Writer it didn't migrate my connection settings properly for Community Server (Blogger was fine). The support of Community Server has been significantly enhanced.
I deleted my connection to Community Server and recreated it - all is fine now.
Bastard Operator from Hell
In my staff meeting today I discovered that not everyone knows of the Bastard Operator from Hell series (BOFH).
The series was written 1998-2001 by Simon Travaglia, though the tourch has been carried on since. I haven't read the latest but there was a time I eagerly awaited the next episode.
Essentially the bastard operator from hell sometimes answers the phone and is quick to doll out advise to unsuspecting callers - advise that occasionally will solve their problem, but usually will just result in removal of their computer privileges.
If you have ever had to answer the questions of the technically inept you will likely find these articles of great humor (especially if you have an appreciation for mainframe/unix systems).