一.WebHostBuilder配置URL和端口進行偵聽 UseUrls()
1.默認的ASP.NET Core項目綁定http://localhost:5000
。通過使用UseUrls
擴展方法——編輯urls
命令行參數
2.指定格式:http://xxx:xxx,如:http://*:81
var host = new WebHostBuilder() // .UseUrls("http://localhost:5003","http://www.sqlme.com:80") //.UseUrls("http://*:8000") .UseUrls("http://www.sqlme.com:8000") .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .UseApplicationInsights() .Build();
3.如果當前機器已經安裝了IIS等服務器軟件,那么監聽 80端口就會拋出異常。
4.如果使用不同的域名共享一個 端口,可以參考WebListener
二、關於ASP.NET Core WebListener 服務器
WebListener支持以下功能:
- Windows Authentication
- Port sharing
- HTTPS with SNI
- HTTP/2 over TLS (Windows 10)
- Direct file transmission
- Response caching
- WebSockets (Windows 8)
支持的Windows版本:
- Windows 7和Windows Server 2008 R2和更高版本
更多 :