Robert McLaws: FunWithCoding.NET

Public Shared Function BrainDump(ByVal dotNet As String) As [Value]

News

<script type="text/javascript"><!-- google_ad_client = "pub-4330602465258980"; google_hints = "ASP.NET, VB.NET, C#, C#.NET, WindowsForms, .NET Framework, VS2005, Visual Studio, XAML, WinFX, Windows Workflow, WPF, WCF, Atlas, NetFX3, Visual Studio Orcas"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="4997399242"; google_color_border = "B6C9E7"; google_color_bg = "EFEFEF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "002C99"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<!--
-->

You should feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever. That said, I will most likely only delete abusive, profane, rude, or annonymous comments, so keep it polite, please.

Blogroll

Cool .NET Articles

My .NET Tools

My Builder.com Articles

My MSKB Articles

"ASP.NET 2.0 Web Server Here" Shell Extension

I've been doing some web development work again lately, and I haven't wanted to screw with setting up IIS on my virtual machine. The .NET Framework 2.0 comes with a built-in webserver, based on the old Cassini web server. So I wanted to be able to easily set up any directory to have its contents served up on an as-needed basis. The result is an addition to the Windows Explorer right-click menu, as shown below:

This is enabled by a simple modification to the registry. You can take the text below and dump it into a file named "WebServer.reg", and then run it, to immediately get the item in the context menu.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer]
@="ASP.NET 2.0 Web Server Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer\command]
@="C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Webdev.WebServer.exe /port:8080 /path:\"%1\""

There are a couple caveats to this tool, however:

  1. The web server does not randomly assign a port number, so it has to be hard-coded into the registry.
  2. The web server does not automatically assign a virtual directory, so it will always be "http://localhost:port"
  3. A command prompt window will be spawned, and cannot be closed without closing the web server process.

Moving foward, there are a couple of options to fix these issues:

  1. Someone who knows more about variables in the registry can help me fix issues #2 and #3
  2. I can build a wrapper executable that solves all three problems
  3. Microsoft can put in a DCR and fix it before it goes gold in a few days.

#3 is not likely, so I'd love to hear what you think. Hope this trick is useful.

Comments

Paul Wilson said:

Cool -- looks very promising. Keep us informed about progress on the remaining "issues".
# October 25, 2005 3:49 PM

Christopher said:

I did the same thing, but used a small wrapper command-line exe.

The only drawback to that method is that the path of the exe needed to be hardcoded into the registry value (i.e. c:\bin\WebDevHere.exe) even when it was in my PATH or under %windir%.

From my limited research, doing a random number in batch language is non-trivial. I even looked at writing a .js file to be executed by cscript, and the best tradeoff that I could come up with was the command line wrapper.
# October 25, 2005 4:07 PM

Daniel Fisher(lennybacon) said:

No drawback at all:

string command =
Path.Combine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(),
"WebDev.WebServer.EXE");
# October 26, 2005 3:44 AM

mihailik said:

It seems WebDev.WebServer is not in .NET Framework itself, but in Visual Studio 2005.

If WebDev.WebServer come to dotnetfx.exe redistributable, it would be great mistake. There are no benefits for plain user to have micro HTTP server. But it may be excellent tool for malware and viruses.

So I hope it is not into redist. If it is into, I will work proactively to remove it (since I am Developer Security MVP) :-)
# October 26, 2005 4:08 AM

Chris Frazier said:

The drawback was that I had to run the command-line exe with a full path, e.g. C:\bin\OpenWebDev.exe "%1" in the registry setting.

Neither putting it in my PATH nor putting it in %windir% helped (I would constantly get a dialog saying that there is no file association for the folder). I guess the commentAPI comments don't work on this blog anymore.
# October 26, 2005 12:42 PM

Robert McLaws said:

I've got a solution that makes the full path a non-issue. I'll blog more about it shortly.

mimalik is right, VS2005 installs the webserver into the .NET directory, it's not in the Framework.
# October 26, 2005 12:45 PM