Pages

Monday, June 15, 2009

WebDev.WebServer

WebDev.WebServer.exe, with .Net Framework 3.5, is located in “%ProgramFiles%\Common Files\microsoft shared\DevServer\9.0\”.

It is a handy small web server that executes .Net code. Combine jQuery UI with server-side support provided by WebServer and back-end code in .Net. Could this replace desktop applications soon?

To run the web server from a batch file, using the folder where the batch file resides as a root, put the following line in the batch file:


"%programfiles%\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" /path:"%cd%"


To create a context menu for a folder that runs the web server in the selected folder, do the steps below. Alternatively, you can copy the following lines into a .reg file and run it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\WebServer]
@="Start Web Server here"

[HKEY_CLASSES_ROOT\Directory\shell\WebServer\command]
@="\"c:\\program files\\Common Files\\microsoft shared\\DevServer\\9.0\\WebDev.WebServer.exe\" /path:\"%L\""

Eventually change the path to %ProgramFiles%. The steps to do this manually are below:

  1. Open Registry Editor (regedit) and go to HKEY_CLASSES_ROOT\Directory\shell,
  2. Create a new Key and give it a meaningful name (WebServer, for example),
  3. Edit the (default) value and enter the description (i.e. "Start Web Server here"),
  4. Add the new sub-key called "command",
  5. Set the (default) value to
    "c:\program files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" /path:"%L"
The results will be visible immediately. Simply right-click any folder and your entry will be there. Clicking it will run the web server in the selected folder. [Check this article for registry locations for context menu handlers.]
Edit the parameters (/port, /path, /vpath) additionally to suit your needs. These values will use default and run the Web Server at port 80 with the URL of "http://localhost/". There is no virtual (sub-)directory. The web server will crash if there is IIS (or another web server) occupying the port.

Another possible way to do this is by using the Windows Scripting Host. Create a .js file with the following contents:


var oShell = new ActiveXObject("WScript.Shell");
var oFSO = new ActiveXObject("Scripting.FileSystemObject");

var sCurFolder = oFSO.GetParentFolderName(WScript.ScriptFullName);
oShell.CurrentDirectory = sCurFolder;

// to display info, use:
// WScript.Echo('wscript.echo');
// oShell.Popup('test');

var wshEnv = oShell.Environment("PROCESS");
var sProgFiles = wshEnv("ProgramFiles");

var cmd = '"' + sProgFiles + '\\Common Files\\microsoft shared\\DevServer\\9.0\\WebDev.WebServer.exe" /path:"' + sCurFolder + '"';

// Run the web server.
oShell.Run(cmd);
// Run the browser.
oShell.Run("http://localhost/");

6 comments:

Anonymous said...

thanks

Anonymous said...

Getting error "Access Denied"
When rt-clicked a folder containg website.

Alen's Australia said...

"Access Denied" might mean your user account does not have read rights on the given folder?
Right-clicking a folder in Windows Explorer should produce standard Windows menu with options for that folder.
Did you apply these settings on the machine? Was the error popping before or only after you added these?

serefbilge said...

When I test connection to oracle database, it is OK. But, when I debug my code, it gives connection error. I use vs 2008 .net; x64 windows 7 ultimate.

I guess what the reason for this problem is pharantheses in the path of Webdev.WbServer.exe, like:
"C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe" How can I fix this? Can I change the folder of WebDev.WebServer.exe? Thanks in advance.

Alen's Australia said...

For any of you having troubles with Cassini, I'd heartily recommend the new IIS Express. Have a look at the announcement at Scott Gu's blog:

http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx

and then download from the link at

http://learn.iis.net/page.aspx/868/iis-express-overview/

Apparently it works on XP and above. This is such a welcome addition to the development suite of tools.

Alen's Australia said...

@serefbilge:

You could try downloading the old Cassini server, which you can place anywhere, or just copy the WebServer.exe some place else.
It is installed by default in the (x86) path because Visual Studio is a 32-bit application.