我有ASP.NET网页,我想为其构建自动化测试(使用WatiN和MBUnit).如何从我的代码启动ASP.Net开发服务器?我不想使用IIS.
这就是我用过的方法:
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...
Run Code Online (Sandbox Code Playgroud)
据我所知,您可以使用以下路径/语法从命令提示符启动dev服务器:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Webdev.WebServer.exe /port:[PORT NUMBER] /path: [PATH TO ROOT]
Run Code Online (Sandbox Code Playgroud)
...所以我可以想象你可以轻松地使用Process.Start()通过一些代码启动你需要的细节.
当然,您需要将该版本号调整为最近/期望的任何值.
| 归档时间: |
|
| 查看次数: |
5721 次 |
| 最近记录: |