我想知道我是否可以重构一个自托管应用程序(启动并显示它提供的 Web 服务的 URL 的控制台应用程序),使其在纯 vnext 而不是 owin 上工作。
owin代码如下
namespace Selfhostingtest
{
class Program
{
static void Main(string[] args)
{
String strHostName = string.Empty;
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
var options = new StartOptions();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
}
}
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Razor server is running. Press enter to shut down...");
Console.ReadLine();
}
}
}
}
作为记录,我不想使用“k web”命令行启动。我想将 vnext 应用程序完全打包为可执行文件。
应该使用 Microsoft.AspNet.Hosting 而不是 Microsoft.Owin.Hosting(与“k web”命令定义中的类相同。请记住,Owin Startup 需要 IAppBuilder 而 vnext 需要 IBuilder。