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

[{'answer_id': 57105, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 4, 'selected': True, 'text': "<p>From what I know, you can fire up the dev server from the command prompt with the following path/syntax:</p>\n\n<pre><code>C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Webdev.WebServer.exe /port:[PORT NUMBER] /path: [PATH TO ROOT]\n</code></pre>\n\n<p>...so I could imagine you could easily use Process.Start() to launch the particulars you need through some code.</p>\n\n<p>Naturally you'll want to adjust that version number to whatever is most recent/desired for you.</p>\n"}, {'answer_id': 57890, 'author': 'Ray', 'author_id': 4872, 'author_profile': 'https://Stackoverflow.com/users/4872', 'pm_score': 3, 'selected': False, 'text': '<p>This is what I used that worked:</p>\n\n<pre><code>using System;\nusing System.Diagnostics;\nusing System.Web;\n...\n\n// settings\nstring PortNumber = "1162"; // arbitrary unused port #\nstring LocalHostUrl = string.Format("http://localhost:{0}", PortNumber);\nstring PhysicalPath = Environment.CurrentDirectory //  the path of compiled web app\nstring VirtualPath = "";\nstring RootUrl = LocalHostUrl + VirtualPath;                 \n\n// create a new process to start the ASP.NET Development Server\nProcess process = new Process();\n\n/// configure the web server\nprocess.StartInfo.FileName = HttpRuntime.ClrInstallDirectory + "WebDev.WebServer.exe";\nprocess.StartInfo.Arguments = string.Format("/port:{0} /path:\\"{1}\\" /virtual:\\"{2}\\"", PortNumber, PhysicalPath, VirtualPath);\nprocess.StartInfo.CreateNoWindow = true;\nprocess.StartInfo.UseShellExecute = false;\n\n// start the web server\nprocess.Start();\n\n// rest of code...\n</code></pre>\n'}, {'answer_id': 19845812, 'author': 'Michael Sorens', 'author_id': 115690, 'author_profile': 'https://Stackoverflow.com/users/115690', 'pm_score': 1, 'selected': False, 'text': '<p>Building upon @Ray Vega\'s useful answer, and @James McLachlan\'s important update for VS2010, here is my implementation to cover VS2012 and fallback to VS2010 if necessary. I also chose not to select only on Environment.Is64BitOperatingSystem because it went awry on my system. That is, I have a 64-bit system but the web server was in the 32-bit folder. My code therefore looks first for the 64-bit folder and falls back to the 32-bit one if necessary.</p>\n\n<pre><code>public void LaunchWebServer(string appWebDir)\n{\n    var PortNumber = "1162"; // arbitrary unused port #\n    var LocalHostUrl = string.Format("http://localhost:{0}", PortNumber);\n    var VirtualPath = "/";\n\n    var exePath = FindLatestWebServer();\n\n    var process = new Process\n    {\n        StartInfo =\n        {\n            FileName = exePath,\n            Arguments = string.Format(\n                "/port:{0} /nodirlist /path:\\"{1}\\" /virtual:\\"{2}\\"",\n                PortNumber, appWebDir, VirtualPath),\n            CreateNoWindow = true,\n            UseShellExecute = false\n        }\n    };\n    process.Start();\n}\n\nprivate string FindLatestWebServer()\n{\n    var exeCandidates = new List&lt;string&gt;\n    {\n        BuildCandidatePaths(11, true), // vs2012\n        BuildCandidatePaths(11, false),\n        BuildCandidatePaths(10, true), // vs2010\n        BuildCandidatePaths(10, false)\n    };\n    return exeCandidates.Where(f =&gt; File.Exists(f)).FirstOrDefault();\n}\n\nprivate string BuildCandidatePaths(int versionNumber, bool isX64)\n{\n    return Path.Combine(\n        Environment.GetFolderPath(isX64\n            ? Environment.SpecialFolder.CommonProgramFiles\n            : Environment.SpecialFolder.CommonProgramFilesX86),\n        string.Format(\n            @"microsoft shared\\DevServer\\{0}.0\\WebDev.WebServer40.EXE",\n            versionNumber));\n}\n</code></pre>\n\n<p>I am hoping that an informed reader might be able to supply the appropriate incantation for VS2013, as it apparently uses yet a different scheme...</p>\n'}, {'answer_id': 24969218, 'author': 'Behzad', 'author_id': 809974, 'author_profile': 'https://Stackoverflow.com/users/809974', 'pm_score': 0, 'selected': False, 'text': "<p>You can easily use <strong>Process Explorer</strong> to find complete command line options needed for manually start it.\nStart Process Explorer while debugging your website. For VS2012, expand 'devenv.exe' node. Right-click on 'WebDev.WebServer20.exe' and from there you can see Path and Command Line values.</p>\n"}]
['https://Stackoverflow.com/questions/57094', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4872/']