Support running under virtual directories

Multiple tweaks + a few hacks to allow running under a virtual directory
in IIS