可以在Web API项目中使用OrchardCore的多个tennant特性吗?
我已经使用"ASP.NET核心Web应用程序“-> "API”模板在Visual Studio中创建了一个空项目,并添加了对OrchardCore.Application.Mvc.Targets的引用。
我的StartUp类如下所示:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOrchardCore().AddMvc().WithTenants();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseOrchardCore(builder =>
{
builder.UseHttpsRedirection();
builder.UseRouting();
builder.UseAuthorization();
builder.UseEndpoints(endpoints => { endpoints.MapControllers(); });
});
}
}我还向appsetting.json添加了以下内容
"OrchardCore": {
"Default": {
"State": "Running",
"RequestUrlHost": null,
"RequestUrlPrefix": null,
"Features": [],
"CustomTitle": "Default Tenant",
"CustomSetting": "Custom setting for Default tenant"
},
"CustomerA": {
"State": "Running",
"RequestUrlHost": null,
"RequestUrlPrefix": "customer-a",
"Features": [ "Module1" ],
"CustomTitle": "Customer A",
"CustomSetting": "Custom setting for Customer A"
},
"CustomerB": {
"State": "Running",
"RequestUrlHost": null,
"RequestUrlPrefix": "customer-b",
"Features": [ "Module1", "Module2" ],
"CustomTitle": "Customer B",
"CustomSetting": "Custom setting for Customer B"
}当我运行应用程序时,默认的https://localhost:44370/weatherforecast路由可以工作,但https://localhost:44370/customer-b/weatherforecast返回404。
我认为这可能是我使用AddControllers或UseOrchardCore的方式。例如,如果我注释掉AddControllers,我会得到一个InvalidOperationException,因为UseAuthorization不再工作。
发布于 2020-10-03 13:53:22
使用Core 3.1
我在StartUp中这样做是为了让我使用控制器而不是页面。请记住,您必须将OrchardCore.Module.Targets添加到每个模块,然后将该模块导入主项目。
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new TenantViewLocationExpander());
});
/*
* Needed for authorization and such.
*/
services.AddControllersWithViews();
/*
* Add multitenancy
*/
services.AddOrchardCore()
.Configure((tenantAppBuilder, endpointBuilder, tenantScopeServiceProvier) =>
{
/*
* Map our routes
*/
endpointBuilder.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
}).AddMvc()
.WithTenants();
}https://stackoverflow.com/questions/62446595
复制相似问题