asp.net Core custom port
Official documents
- Source code of aspnet internal library: https://github.com/aspnet
- Source code of internal library of dotnet system: https://github.com/dotnet
- Official document of asp.net core
Custom port access
- webHost adds UseUrls. Example: WebHost.UseUrls("http://:5001","http://:5002");
- The configuration file hosting.json. Example:
By viewing WebHost We learned from the source code that the configuration parameters will be read first after startup,
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(); }
- Configure environment variables. Set the values of aspnetcore? URLs, aspnet? Env, aspnetcore? Server.urls.
Web server
- Kestrel (default)
- Http.sys (does not work in reverse proxy configuration using IIS)
- Custom server
Hosting and deployment
- linux
- centos7.2
- windows
- IIS
- windows services