asp.net core custom port

asp.net Core custom port

Official documents

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

Official documents

Hosting and deployment

Official hosting and deployment documentation

  • linux
  • centos7.2
  • windows
  • IIS

asp.net core deploy iis win7/win10

  • windows services

Tags: IIS github JSON Windows

Posted on Mon, 27 Apr 2020 10:23:56 -0400 by toro04