下面是用于在wwwroot之外提供静态文件的代码 //在wwwroot之外提供静态文件
public static IApplicationBuilder UseClientStaticResources(this IApplicationBuilder app, HostingEnvironment env, IConfiguration Configuration, string site)
{
var path = Path.Combine(env.ContentRootPath, "sites/client1/web/assets"); // this allows for serving up contents in a folder named 'static'
var provider = new PhysicalFileProvider(path);
var options = new StaticFileOptions();
options.RequestPath = ""; // an empty string will give the *appearance* of it being served up from the root
//options.RequestPath = "/content"; // this will use the URL path named content, but could be any made-up name you want
options.FileProvider = provider;
app.UseStaticFiles(options);
return app;
}
public static IApplicationBuilder UseTemplateStaticResources(this IApplicationBuilder app, HostingEnvironment env, IConfiguration Configuration, string template)
{
var path = Path.Combine(env.ContentRootPath, "sites/_templates/template1/web/assets"); // this allows for serving up contents in a folder named 'static'
var provider = new PhysicalFileProvider(path);
var options = new StaticFileOptions();
options.RequestPath = ""; // an empty string will give the *appearance* of it being served up from the root
//options.RequestPath = "/content"; // this will use the URL path named content, but could be any made-up name you want
options.FileProvider = provider;
app.UseStaticFiles(options);
return app;
}
在appsettings.json中,我们定义了像
这样的结构"Multitenancy": {
"Tenants": [
{
"client": "client1",
"host": "localhost:5000"
},
{
"client": "client2",
"host": "localhost:6000"
}
]
}
并使用
string client = context.ActionContext.HttpContext.GetTenant<AppTenant>()?.client;
我正在尝试根据我们在UseClientStaticResources / UseTemplateStaticResources扩展方法中浏览的主机网址获取“client1”或“client2”。
如何使用SaasKit获取租户信息?
这可以在这种情况下获得上下文吗?