lith преди 4 години
родител
ревизия
d6cb4fd958

+ 1 - 1
dotnet/Gateway/App.Gateway/appsettings.json

@@ -75,7 +75,7 @@
           //"requestPath": "/file",
 
           /* 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot/demo" */
-          "rootPath": "wwwroot",
+          //"rootPath": "wwwroot",
 
           /* 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering  may affect performance */
           //"defaultFileNames": [],

+ 1 - 1
dotnet/Gateway/Sers.Gateway/Sers.Gateway/GatewayHelp.cs

@@ -65,7 +65,7 @@ namespace Sers.Gateway
             Logger.Info("[WebHost]will listening on: " + string.Join(",", arg.urls));
 
             if (arg.staticFiles?.rootPath != null)
-                Logger.Info("[WebHost]wwwroot : " + arg.staticFiles?.rootPath);
+                Logger.Info("[WebHost]wwwroot : " + arg.staticFiles.rootPath);
 
             Vit.WebHost.Host.Run(arg);
             #endregion

+ 16 - 5
dotnet/Library/Vit/Vit.WebHost/Extensions/IApplicationBuilderExtensions_UseStaticFiles.cs

@@ -1,5 +1,6 @@
 using Microsoft.AspNetCore.Builder;
 using Microsoft.Extensions.FileProviders;
+using System.IO;
 using Vit.Core.Util.Common;
 using Vit.WebHost;
 
@@ -23,17 +24,27 @@ namespace Vit.Extensions
             }
 
 
-            //(x.x.2)FileProvider
-            IFileProvider fileProvider;
-            if (!string.IsNullOrWhiteSpace(config.rootPath))
+            #region (x.x.2)FileProvider
+            IFileProvider fileProvider=null;
+            string rootPath;
+
+            if (!string.IsNullOrWhiteSpace(rootPath=config.rootPath) && Directory.Exists(rootPath))
+            {
+                fileProvider = new PhysicalFileProvider(rootPath);
+            }
+            else if (Directory.Exists(rootPath = CommonHelp.GetAbsPath("wwwroot")))
             {
-                fileProvider = new PhysicalFileProvider(config.rootPath);
+                fileProvider = new PhysicalFileProvider(rootPath);
             }
             else 
             {
-                fileProvider = new PhysicalFileProvider(CommonHelp.GetAbsPath("wwwroot"));
+                var dir = new DirectoryInfo("wwwroot");
+                if(dir.Exists)
+                    fileProvider = new PhysicalFileProvider(dir.FullName);
             }
             staticfileOptions.FileProvider = fileProvider;
+            #endregion
+
 
             //(x.x.3)OnInitStaticFileOptions
             config.OnInitStaticFileOptions?.Invoke(staticfileOptions);

+ 1 - 1
dotnet/Library/Vit/Vit.WebHost/appsettings.json

@@ -24,7 +24,7 @@
           //"requestPath": "/file",
 
           /* 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot/demo" */
-          "rootPath": "wwwroot",
+          //"rootPath": "wwwroot",
 
           /* 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering  may affect performance */
           //"defaultFileNames": [],

+ 1 - 1
dotnet/ServiceCenter/App.Gover.Gateway/appsettings.json

@@ -74,7 +74,7 @@
           //"requestPath": "/file",
 
           /* 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot/demo" */
-          "rootPath": "wwwroot",
+          //"rootPath": "wwwroot",
 
           /* 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering  may affect performance */
           "defaultFileNames": ["index.html"],

+ 1 - 1
dotnet/ServiceCenter/App.ServiceCenter/appsettings.json

@@ -425,7 +425,7 @@
           //"requestPath": "/file",
 
           /* 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot/demo" */
-          "rootPath": "wwwroot",
+          //"rootPath": "wwwroot",
 
           /* 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering  may affect performance */
           "defaultFileNames": [ "index.html" ],