Asp.net mvc 如何使用weboptimizer处理多个虚拟目录和单个wwwroot
ASP.NET 5 MVC核心应用程序使用LigerShark WebOptimizer()为多个站点提供服务 所有这些站点都应该从包含这些URL的相同文件的wwwroot目录提供服务。 站点在hosts.json文件中定义:Asp.net mvc 如何使用weboptimizer处理多个虚拟目录和单个wwwroot,asp.net-mvc,asp.net-core,asp.net-core-mvc,.net-5,web-optimization,Asp.net Mvc,Asp.net Core,Asp.net Core Mvc,.net 5,Web Optimization,ASP.NET 5 MVC核心应用程序使用LigerShark WebOptimizer()为多个站点提供服务 所有这些站点都应该从包含这些URL的相同文件的wwwroot目录提供服务。 站点在hosts.json文件中定义: { "EevaHosts": { "example.com/store1": {} "example.com/store2": {} "example2.com":
{
"EevaHosts": {
"example.com/store1": {}
"example.com/store2": {}
"example2.com": {}
}
}
我尝试了下面的代码来强制WebOptimizer对DebianLinux中的每个站点使用相同的WWroot目录,但遇到了异常
在中找不到与“/store1/js/site.js”匹配的文件
“/var/www/appbasedir/wwwroot/”
如何强制web优化器对所有站点使用相同的WWroot目录?
如果删除Weboptimizer中间件,静态文件将被正确地服务器化
在StartUp.cs中:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ ...
var eevakonf = new ConfigurationBuilder().AddJsonFile("hosts.json").Build();
foreach (var host1 in eevakonf.GetSection("EevaHosts").GetChildren())
{
if (!host1.Key.Contains("/"))
app.UseWebOptimizer();
else
app.UseWebOptimizer(env, new FileProviderOptions[] { new FileProviderOptions()
{
// example.com/store1 -> /store1
RequestPath = new PathString(RequestPathExtract(host1)),
FileProvider = env.WebRootFileProvider
}
});
}
// Using single call causes the same exception:
//HashSet<FileProviderOptions> fp = new();
//foreach (var host1 in eevakonf.GetSection("EevaHosts").GetChildren())
//{
// if (host1.Key.Contains("/"))
// fp.Add(new FileProviderOptions() {
// RequestPath = new PathString(RequestPathExtract(host1)) ,
// FileProvider = env.WebRootFileProvider
// });
//}
//app.UseWebOptimizer(env, fp.ToArray());
foreach (var host in eevakonf.GetSection("EevaHosts").GetChildren())
{
if (!host.Key.Contains("/"))
app.UseStaticFiles();
else
{
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString(RequestPathExtract(host))
});
}
}
}
static string RequestPathExtract(IConfigurationSection host)
{
return "/" + StrExtract(host.Key, "/");
}
static string StrExtract(string cSearchExpression, string cBeginDelim)
{
int nbpos = At(cBeginDelim, cSearchExpression);
return cSearchExpression[(nbpos + cBeginDelim.Length - 1)..];
}
public void配置(IApplicationBuilder应用程序,IWebHostEnvironment环境)
{ ...
var eevakonf=new ConfigurationBuilder().AddJsonFile(“hosts.json”).Build();
foreach(eevakonf.GetSection(“EevaHosts”).GetChildren()中的var host1)
{
如果(!host1.Key.Contains(“/”)
app.UseWebOptimizer();
其他的
app.UseWebOptimizer(env,newFileProviderOptions[]{newFileProviderOptions()
{
//example.com/store1->/store1
RequestPath=新路径字符串(RequestPathExtract(host1)),
FileProvider=env.WebRootFileProvider
}
});
}
//使用单个调用会导致相同的异常:
//HashSet fp=new();
//foreach(eevakonf.GetSection(“EevaHosts”).GetChildren()中的var host1)
//{
//if(host1.Key.Contains(“/”)
//fp.Add(新的FileProviderOptions(){
//RequestPath=新路径字符串(RequestPathExtract(host1)),
//FileProvider=env.WebRootFileProvider
// });
//}
//app.UseWebOptimizer(env,fp.ToArray());
foreach(eevakonf.GetSection(“EevaHosts”).GetChildren()中的变量主机)
{
如果(!host.Key.Contains(“/”)
app.UseStaticFiles();
其他的
{
app.UseStaticFiles(新的StaticFileOptions
{
RequestPath=新路径字符串(RequestPathExtract(主机))
});
}
}
}
静态字符串RequestPathExtract(IConfigurationSection主机)
{
返回“/”+StrExtract(host.Key“/”;
}
静态字符串StrExtract(字符串cSearchExpression、字符串cBeginDelim)
{
int nbpos=At(cBeginDelim,cSearchExpression);
返回cSearchExpression[(nbpos+cBeginDelim.Length-1)];
}
不确定是否相关。但是webOptimizer不支持.NETCore5.0。不同的问题对我来说,但我注意到这一点,而使蔚蓝的管线。是.NET核心中间件。它是为.NET内核设计的,在.NET 5中工作
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ ...
var eevakonf = new ConfigurationBuilder().AddJsonFile("hosts.json").Build();
foreach (var host1 in eevakonf.GetSection("EevaHosts").GetChildren())
{
if (!host1.Key.Contains("/"))
app.UseWebOptimizer();
else
app.UseWebOptimizer(env, new FileProviderOptions[] { new FileProviderOptions()
{
// example.com/store1 -> /store1
RequestPath = new PathString(RequestPathExtract(host1)),
FileProvider = env.WebRootFileProvider
}
});
}
// Using single call causes the same exception:
//HashSet<FileProviderOptions> fp = new();
//foreach (var host1 in eevakonf.GetSection("EevaHosts").GetChildren())
//{
// if (host1.Key.Contains("/"))
// fp.Add(new FileProviderOptions() {
// RequestPath = new PathString(RequestPathExtract(host1)) ,
// FileProvider = env.WebRootFileProvider
// });
//}
//app.UseWebOptimizer(env, fp.ToArray());
foreach (var host in eevakonf.GetSection("EevaHosts").GetChildren())
{
if (!host.Key.Contains("/"))
app.UseStaticFiles();
else
{
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString(RequestPathExtract(host))
});
}
}
}
static string RequestPathExtract(IConfigurationSection host)
{
return "/" + StrExtract(host.Key, "/");
}
static string StrExtract(string cSearchExpression, string cBeginDelim)
{
int nbpos = At(cBeginDelim, cSearchExpression);
return cSearchExpression[(nbpos + cBeginDelim.Length - 1)..];
}