asp.net Core 自定義端口
官方文檔
- aspnet内庫源碼: https://github.com/aspnet
- dotnet系統内庫源碼:https://github.com/dotnet
-
asp.net core 官方文檔
自定義端口通路
- webHost增加UseUrls。 例:WebHost.UseUrls("http://:5001","http://:5002");
- 配置檔案 hosting.json。例:
通過檢視WebHost源碼我們得知,啟動後會先讀取相關配置參數,
internal class WebHost:IWebHost
{
private static readonly string DeprecatedServerUrlsKey = "server.urls";
//...
private void EnsureServer()
{
if (Server == null)
{
//...
if (addresses != null && !addresses.IsReadOnly && addresses.Count == 0)
{
var urls = _config[WebHostDefaults.ServerUrlsKey] ?? _config[DeprecatedServerUrlsKey];
}
}
}
}
public static class WebHostDefaults{
public static readonly string ServerUrlsKey = "urls";
//...
}
{"server.urls": "http://localhost:5003;http://localhost:5004"}
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", true)
.Build();
BuildWebHost(args, config).Run();
//BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args, IConfiguration config) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
// .UseUrls("http://*:5001", "http://*:5002")
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
}
- 配置環境變量。設定ASPNETCORE_URLS、ASPNET_ENV、ASPNETCORE_SERVER.URLS的值。
Web伺服器
- Kestrel(預設)
- HTTP.sys(在使用 IIS 的反向代理配置中不起作用)
- 自定義伺服器
> 官方文檔
托管和部署
官方托管和部署文檔
- linux
- centos7.2
- windows
- IIS
asp.net core 部署iis win7/win10
- windows服務
- IIS
轉載于:https://www.cnblogs.com/lenovo_tiger_love/p/9522838.html