diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index 2e6cbed..f4126c6 100644 --- a/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net.csproj @@ -17,7 +17,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.4.3 + 1.4.4 Logo_Symbol_Black_Outline.png diff --git a/Rest.Net/RouteListener.cs b/Rest.Net/RouteListener.cs index 559ee2b..21b66a2 100644 --- a/Rest.Net/RouteListener.cs +++ b/Rest.Net/RouteListener.cs @@ -93,18 +93,29 @@ namespace MontoyaTech.Rest.Net { this.HttpListener = new HttpListener(); - //Support listening on Windows & Linux. - if (Environment.OSVersion.Platform == PlatformID.Win32NT) - { - this.HttpListener.Prefixes.Add($"http://localhost:{this.Port}/"); - this.HttpListener.Prefixes.Add($"http://127.0.0.1:{this.Port}/"); - } - else - { - this.HttpListener.Prefixes.Add($"http://*:{this.Port}/"); - } + //Attempt to listen on all interfaces first. + this.HttpListener.Prefixes.Add($"http://*:{this.Port}/"); - this.HttpListener.Start(); + try + { + this.HttpListener.Start(); + } + catch (HttpListenerException ex) + { + //If this failed and it's because we are not admin, try again with the local prefixes + if (ex.Message.ToLower().StartsWith("access is denied")) + { + this.HttpListener = new HttpListener(); + this.HttpListener.Prefixes.Add($"http://localhost:{this.Port}/"); + this.HttpListener.Prefixes.Add($"http://127.0.0.1:{this.Port}/"); + + this.HttpListener.Start(); + } + else + { + throw; + } + } this.Listen(); }