Skip to content

Instantly share code, notes, and snippets.

@miclip
Last active August 20, 2021 17:51
Show Gist options
  • Save miclip/29c3c1934608fd2c8224b10be72cbe4b to your computer and use it in GitHub Desktop.
Save miclip/29c3c1934608fd2c8224b10be72cbe4b to your computer and use it in GitHub Desktop.

Update the WebHostBuilder call to include .UseUrls(GetServerUrls(args))

var host = new WebHostBuilder()
                .UseKestrel()
                .UseUrls(GetServerUrls(args))
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();

Then add this static method to the Program.cs

private static string[] GetServerUrls(string[] args)
{
    List<string> urls = new List<string>();
    for (int i = 0; i < args.Length; i++)
    {
      if ("--server.urls".Equals(args[i], StringComparison.OrdinalIgnoreCase))
      {
        urls.Add(args[i + 1]);
      }
    }
    return urls.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment