Visual Studio 2005 Websites and Web Application projects use the ASP.NET Development Server as a light-weight web server to host the websites. Pretty easy, but sometimes you need to host one or more websites and don’t feel like starting a full-blown VS2005 instance just for that. And adding a Web Share or creating a virtual directory and application in IIS seems like too much hassle and meshes your IIS server up. Here’s your way out:
Run a Visual Studio 2005 Command Prompt and run this command:
WebDev.Webserver.exe /path:”C:WebsiteThatIDontWantToSetupinIIS” /port:1337
This will allow you to access the web pages and services from URLs like http://localhost:1337/MyPage.aspx. If you want a virtual path in the URL you can specify so with the vpath option: /vpath:MyWebsite as an extra parameter. When you forgot what the parameters were all about, simply run without any parameters and you will get a dialog explaining all (well, not the answer to everything (42 by the way)).
Some gotchas and tips that came to mind:
- Not really suitable if you want security to play an important part
- localhost addresses only.
You cannot even use aliases for 127.0.0.1 other than localhost, because they will be denied.
- Remember to always put http:// in front of the URL if you are using a portnumber other than 80.
Just one of those things.
- Create a batch file if you need to host multiple sites all the time (without hosting it in IIS) to fire up more than one instances. Don’t let me catch you running VS2005 instances for that purpose (and there are people out there who did. They know who I am talking about.)
But, since a call to WebDev.WebServer.exe will block, you will have to throw in some batch script magic like start to get things working all right.
The core of the application is provided by the GAC registered WebDev.WebHost.dll which resides at the location C:WINDOWSassemblyGAC_32WebDev.WebHost184.108.40.206__b03f5f7f11d50a3a. You can reach it from the command prompt and open it up using Reflector or ILDASM. You can have loads of fun with this assembly and put it to good use. See how you can use it in your unit tests on Phil Haack’s blog, creator of the SubText blogging engine.