设置Urls和Port ASPNET核心应用程序自托管Windows服务

时间:2020-04-15 17:24:36

标签: asp.net-core command-line configuration

我正在尝试在自托管的Web API中覆盖默认的红k URL /端口绑定5000。

我想将其作为Windows服务运行。理想情况下,在安装服务时,我希望将端口设置为侦听。即

sc create MyApi binPath= "\MyApi.exe --urls "http://*:6050"

我无法覆盖url属性。我已经在Windows服务之外尝试过:

MyApi.exe --urls "http://*:6050"

and even in code

 public static void Main(string[] args)
    {
        var host = Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureWebHostDefaults(webHostBuilder =>
            {
                webHostBuilder
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseUrls("http://*:6050")
                    .UseStartup<Startup>();
            })
            .UseWindowsService()
            .Build();

        host.Run();
    }

0 个答案:

没有答案