ASP.NET Core Web应用程序的Web.config设置作为ASP.NET Core Web应用程序中的子应用程序?

时间:2021-10-25 20:08:33

Have "WebsiteA" trying to host another application "API" within it. Using a folder called "services". From what I've read in order for the sub-app to work I have to move my handlers up to the parent config. So being new to .NET Core I'm sure I'm missing something straightforward but set up the handlers in the parent something like this:

让“WebsiteA”尝试在其中托管另一个应用程序“API”。使用名为“services”的文件夹。从我读到的内容为了使子应用程序工作,我必须将我的处理程序移动到父配置。所以,对于.NET Core来说,我确信我错过了一些直截了当的东西但是在父代中设置了这样的处理程序:

    <system.webServer>
    <handlers>
      <add name="aspNetCoreAPI" path="services\*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />

    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\websiteA.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />

    <aspNetCoreAPI processPath="dotnet" arguments=".\services\api.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />


  </system.webServer>

Seems that the aspNetCoreAPI tag is a no-no as the application rejects the configuration as malformed.

似乎aspNetCoreAPI标签是禁忌,因为应用程序拒绝配置为格式错误。

Ideally how should the web.config be setup in a the sub-application scenario for such an api application?

理想情况下,如何在这种api应用程序的子应用程序场景中设置web.config?

1 个解决方案

#1


1  

Yeah so the config approach is completely not right. Keeping the config vanilla in the parent app and making a simple handler exclusion (commented out) in the child application makes the magic happen for configuration issues.

是的,配置方法完全不对。将配置文件保存在父应用程序中并在子应用程序中进行简单的处理程序排除(注释掉)会使配置问题变得神奇。

Parent:

家长:

<system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\websiteA.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>

Child:

儿童:

<system.webServer>
    <handlers>
      <!--<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />-->

    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\api.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>

They real key is that you need to make a really gross addition to the parent Configure method in the Startup.cs. (https://github.com/aspnet/Hosting/issues/416#issuecomment-149046552)

真正的关键是你需要在Startup.cs中对父配置方法做一个非常重要的补充。 (https://github.com/aspnet/Hosting/issues/416#issuecomment-149046552)

So I added this at the bottom of the existing logic in the method:

所以我在方法的现有逻辑的底部添加了这个:

app.Map("/services", (app1) => this.Configure1(app1, env, loggerFactory));

and in the new Configure1 method created I copied the Configure method from my child application:

并在创建的新Configure1方法中,我从我的子应用程序复制了Configure方法:

public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc();
        }

I don't prefer the child app directory path and sub-application logic in my parent app as it is a tightly leashed coupling that just feels wrong. But that is where things stand right now as I understand.

我不喜欢我的父应用程序中的子应用程序目录路径和子应用程序逻辑,因为它是一个紧绷的耦合,只是感觉不对。但据我所知,这就是现在的事情。

#1


1  

Yeah so the config approach is completely not right. Keeping the config vanilla in the parent app and making a simple handler exclusion (commented out) in the child application makes the magic happen for configuration issues.

是的,配置方法完全不对。将配置文件保存在父应用程序中并在子应用程序中进行简单的处理程序排除(注释掉)会使配置问题变得神奇。

Parent:

家长:

<system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\websiteA.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>

Child:

儿童:

<system.webServer>
    <handlers>
      <!--<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />-->

    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\api.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>

They real key is that you need to make a really gross addition to the parent Configure method in the Startup.cs. (https://github.com/aspnet/Hosting/issues/416#issuecomment-149046552)

真正的关键是你需要在Startup.cs中对父配置方法做一个非常重要的补充。 (https://github.com/aspnet/Hosting/issues/416#issuecomment-149046552)

So I added this at the bottom of the existing logic in the method:

所以我在方法的现有逻辑的底部添加了这个:

app.Map("/services", (app1) => this.Configure1(app1, env, loggerFactory));

and in the new Configure1 method created I copied the Configure method from my child application:

并在创建的新Configure1方法中,我从我的子应用程序复制了Configure方法:

public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc();
        }

I don't prefer the child app directory path and sub-application logic in my parent app as it is a tightly leashed coupling that just feels wrong. But that is where things stand right now as I understand.

我不喜欢我的父应用程序中的子应用程序目录路径和子应用程序逻辑,因为它是一个紧绷的耦合,只是感觉不对。但据我所知,这就是现在的事情。