Allow changing listening ip addresses (#1713)
* Allow changing listening ip address * Use Json serialize for appsettings.config saving * BOM * IP Address validation * ip address reset * ValidIpAddress regex
This commit is contained in:
parent
01aed6ad99
commit
11cb2cfb17
13 changed files with 194 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
|
@ -173,7 +173,25 @@ public class Program
|
|||
{
|
||||
webBuilder.UseKestrel((opts) =>
|
||||
{
|
||||
opts.ListenAnyIP(HttpPort, options => { options.Protocols = HttpProtocols.Http1AndHttp2; });
|
||||
var ipAddresses = Configuration.IpAddresses;
|
||||
if (ipAddresses == null || ipAddresses.Length == 0)
|
||||
{
|
||||
opts.ListenAnyIP(HttpPort, options => { options.Protocols = HttpProtocols.Http1AndHttp2; });
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(var ipAddress in ipAddresses.Split(','))
|
||||
{
|
||||
try {
|
||||
var address = System.Net.IPAddress.Parse(ipAddress.Trim());
|
||||
opts.Listen(address, HttpPort, options => { options.Protocols = HttpProtocols.Http1AndHttp2; });
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Could not parse ip addess '{0}'", ipAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
webBuilder.UseStartup<Startup>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue