gpt4 book ai didi

c# - 如何使用 C# 以编程方式运行 ASP.Net 开发服务器?

转载 作者:可可西里 更新时间:2023-11-01 08:41:51 24 4
gpt4 key购买 nike

我有 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...

关于c# - 如何使用 C# 以编程方式运行 ASP.Net 开发服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com