Home > Uncategorized > ASP.NET Testing Server

ASP.NET Testing Server

November 25th, 2007 Leave a comment Go to comments

Here is a couple of neat tricks from Robert McClaws describing how to serve up a ASP.NET 2.0 folder – perfect for development and testing.

From the command line:
"C:WINDOWSMicrosoft.NETFrameworkv2.0.50727WebDev.WebServer.exe" /path:[PATH OF YOUR WEB APP] /port:[WEB PORT] /vpath:[/mywebapp]

Or to add a web server extension to Windows Explorer (so you can just right click the folder), add the following registry entries:

[HKEY_LOCAL_MACHINESOFTWAREClassesFoldershellVS2005 WebServer]
@=”ASP.NET 2.0 Web Server Here”

[HKEY_LOCAL_MACHINESOFTWAREClassesFoldershellVS2005 WebServercommand]
@=”C:WindowsMicrosoft.NETFrameworkv2.0.50727Webdev.WebServer.exe /port:8080 /path:”%1″”

Chris Frazier added this small program to work around some of the problems mentioned here with this trick:
using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace OpenCassini
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string path;

string command =
@”C:WINDOWSMicrosoft.NETFrameworkv2.0.50727WebDev.WebServer.EXE”;
string commandArgs = string.Empty;

Random r = new Random();

string port = r.Next(1024, 9000).ToString();

if(args.Length == 1){
//grab the original path
path = args[0];

commandArgs += ” /path:”” + path + “””;
commandArgs += ” /port:”;
commandArgs += port;
commandArgs += ” /vpath: “/”;
commandArgs += path.Substring(path.LastIndexOf(”) + 1);
commandArgs += “””;

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

info.Arguments = commandArgs;
info.CreateNoWindow = true;
info.FileName = command;
info.UseShellExecute = false;
info.WorkingDirectory = command.Substring(0, command.LastIndexOf(”));

Process.Start(info);

using(Control c = new Control()){
Help.ShowHelp(c, “https://localhost:” + port + “/”);
}
}
}
}
}

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.