Pārlūkot izejas kodu

修复WebHost当主端口被占用应启用备用端口而不是直接不起Web的问题

felix 8 mēneši atpakaļ
vecāks
revīzija
25f0f426c4
1 mainītis faili ar 8 papildinājumiem un 2 dzēšanām
  1. 8 2
      Vinno.FIS.Sonopost/WebHost.cs

+ 8 - 2
Vinno.FIS.Sonopost/WebHost.cs

@@ -51,9 +51,11 @@ namespace Vinno.FIS.Sonopost
             if (CheckPortInUse(mainPort))
             {
                 Logger.WriteLineWarn($"[{nameof(WebHost)}]{nameof(StartHttp)}:Port {mainPort} is occupied.");
-                return;
             }
-            _httpListener.Prefixes.Add($"http://*:{mainPort}/");
+            else
+            {
+                _httpListener.Prefixes.Add($"http://*:{mainPort}/");
+            }
 
             if (standbyPort > -1)
             {
@@ -66,6 +68,10 @@ namespace Vinno.FIS.Sonopost
                     _httpListener.Prefixes.Add($"http://*:{standbyPort}/");
                 }
             }
+            if (_httpListener.Prefixes.Count == 0)
+            {
+                return;
+            }
             try
             {
                 _httpListener.Start();