首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Web Api的OrchardCore多层应用程序

带有Web Api的OrchardCore多层应用程序
EN

Stack Overflow用户
提问于 2020-06-18 17:19:57
回答 1查看 246关注 0票数 1

可以在Web API项目中使用OrchardCore的多个tennant特性吗?

我已经使用"ASP.NET核心Web应用程序“-> "API”模板在Visual Studio中创建了一个空项目,并添加了对OrchardCore.Application.Mvc.Targets的引用。

我的StartUp类如下所示:

代码语言:javascript
复制
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添加了以下内容

代码语言:javascript
复制
"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。

我认为这可能是我使用AddControllersUseOrchardCore的方式。例如,如果我注释掉AddControllers,我会得到一个InvalidOperationException,因为UseAuthorization不再工作。

EN

回答 1

Stack Overflow用户

发布于 2020-10-03 13:53:22

使用Core 3.1

我在StartUp中这样做是为了让我使用控制器而不是页面。请记住,您必须将OrchardCore.Module.Targets添加到每个模块,然后将该模块导入主项目。

代码语言:javascript
复制
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();
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62446595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档