views:

1331

answers:

2

I have ASP.NET web pages for which I want to build automated tests (using WatiN & MBUnit). How do I start the ASP.Net Development Server from my code? I do not want to use IIS.

+3  A: 

From what I know, you can fire up the dev server from the command prompt with the following path/syntax:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\Webdev.WebServer.exe /port:[PORT NUMBER] /path: [PATH TO ROOT]

...so I could imagine you could easily use Process.Start() to launch the particulars you need through some code.

Naturally you'll want to adjust that version number to whatever is most recent/desired for you.

Dillie-O
If webdev.webserver.exe is not located in that folder, it could be located in C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0 (that's where I found it)
Casper
Casper thank you!
Anders
+4  A: 

This is what I used that worked:

using System;
using System.Diagnostics;
using System.Web;
...

// settings
string PortNumber = "1162"; // arbitrary unused port #
string LocalHostUrl = string.Format("http://localhost:{0}", PortNumber);
string PhysicalPath = Environment.CurrentDirectory //  the path of compiled web app
string VirtualPath = "";
string RootUrl = LocalHostUrl + VirtualPath;           

// create a new process to start the ASP.NET Development Server
Process process = new Process();

/// configure the web server
process.StartInfo.FileName = HttpRuntime.ClrInstallDirectory + "WebDev.WebServer.exe";
process.StartInfo.Arguments = string.Format("/port:{0} /path:\"{1}\" /virtual:\"{2}\"", PortNumber, PhysicalPath, VirtualPath);
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;

// start the web server
process.Start();

// rest of code...
Ray Vega
So did that work for you?
Dillie-O
Thanks for posting the code! :)
Paolo Tedesco