Browse Source

1. 修改取虛擬路徑方式

PTD
Ray 2 years ago
parent
commit
0bef1b0c3e
  1. 27
      AMESCoreStudio.Web/Code/VirtualPathConfig.cs
  2. 55
      AMESCoreStudio.Web/Startup.cs
  3. 15
      AMESCoreStudio.Web/appsettings.json

27
AMESCoreStudio.Web/Code/VirtualPathConfig.cs

@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace AMESCoreStudio.Web.Code
{
/// <summary>
/// 虛擬路徑
/// </summary>
public class VirtualPathConfig
{
public List<PathContent> VirtualPath { get; set; }
}
public class PathContent
{
/// <summary>
/// 真實路徑
/// </summary>
public string RealPath { get; set; }
/// <summary>
/// 目錄名稱
/// </summary>
public string RequestPath { get; set; }
//public string Alias { get; set; }
}
}

55
AMESCoreStudio.Web/Startup.cs

@ -14,6 +14,7 @@ using WebApiClient;
using System.Globalization; using System.Globalization;
using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using AMESCoreStudio.Web.Code;
namespace AMESCoreStudio.Web namespace AMESCoreStudio.Web
{ {
@ -34,31 +35,45 @@ namespace AMESCoreStudio.Web
// 郎�ヘ魁 // 郎�ヘ魁
//Add our IFileServerProvider implementation as a singleton //Add our IFileServerProvider implementation as a singleton
services.AddSingleton<IFileServerProvider>(new FileServerProvider( //services.AddSingleton<IFileServerProvider>(new FileServerProvider(
new List<FileServerOptions> // new List<FileServerOptions>
// {
// new FileServerOptions
// {
// // ¹êÅé¸ô®|
// FileProvider = new PhysicalFileProvider(@"\\10.0.8.7\\shop"),
// // µêÀÀ¸ô®|
// RequestPath = new PathString("/aa"),
// EnableDirectoryBrowsing = true
// }
// new FileServerOptions
// {
// FileProvider = new PhysicalFileProvider(@"//qasrv-n/Web/ISOZone/"),
// RequestPath = new PathString("/DocEsop"),
// EnableDirectoryBrowsing = true
// }
// }));
var config = Configuration.Get<VirtualPathConfig>().VirtualPath;
var fileServerOptions = new List<FileServerOptions>();
if (config != null)
{
config.ForEach(f =>
{ {
//new FileServerOptions fileServerOptions.Add(new FileServerOptions
//{
// // ¹êÅé¸ô®|
// FileProvider = new PhysicalFileProvider(@"\\10.0.8.7\\shop"),
// // µêÀÀ¸ô®|
// RequestPath = new PathString("/aa"),
// EnableDirectoryBrowsing = true
//}
new FileServerOptions
{ {
FileProvider = new PhysicalFileProvider(@"//qasrv-n/Web/ISOZone/"), FileProvider = new PhysicalFileProvider(@f.RealPath),
RequestPath = new PathString("/DocEsop"), RequestPath = new PathString(f.RequestPath),
EnableDirectoryBrowsing = true });
} });
})); };
services.AddSingleton<IFileServerProvider>(new FileServerProvider(fileServerOptions));
// 配置跨域处理,允许所有来源 // 配置跨域处理,允许所有来源
services.AddCors(options => services.AddCors(options =>
options.AddPolicy("AMESPolicy", options.AddPolicy("AMESPolicy",
p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
services.AddLocalization(o => services.AddLocalization(o =>
{ {

15
AMESCoreStudio.Web/appsettings.json

@ -11,6 +11,17 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
// "WipSpecial": "Y",
"WipSpecial": "Y" //
"VirtualPath": [
//{
// "RealPath": "//qasrv-n/Web/ISOZone/", //
// "RequestPath": "/DocEsop" //
//}
//{
// "RealPath": "//10.1.8.1/sop/機種", //
// "RequestPath": "/test"
// //"Alias": "second"
//}
]
} }

Loading…
Cancel
Save