我有以下代码用于将发布的ASP.NET Core 3.1构建作为Windows服务托管:
var builder = WebHost.CreateDefaultBuilder(args);
if (!Debugger.IsAttached)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
builder.UseContentRoot(pathToContentRoot);
}
else
{
builder.UseContentRoot(System.IO.Directory.GetCurrentDirectory());
}
var host = builder.UseStartup<Startup>()
.Build();
if (Debugger.IsAttached)
host.Run();
else
host.RunAsService()
这工作正常,当我启动服务时,可以使用默认的http://localhost:5000网址查看我的页面。可以使用https://localhost:443代替Windows服务将.net核心Web应用程序托管为Windows服务吗?
我尝试添加 builder.UseStartup()。UseUrls(“ https:// *:443”).Build(),但是该服务无法启动,并抛出了系统错误1064 。但是,如果我将其作为独立的可执行文件运行,则可以在端口443上访问该应用程序。