带有Autofac的ASP.NETCore3忽略iis设置;日志显示";现在收听:http://localhost:5000"

带有Autofac的ASP.NETCore3忽略iis设置;日志显示";现在收听:http://localhost:5000",.net,asp.net-core,autofac,asp.net-core-3.0,.net,Asp.net Core,Autofac,Asp.net Core 3.0,我正在使用Autofac运行Asp.net core 3.0 web API。其入口点如下所示: using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using System; using System.IO; namespace Myapp { public class Program {

我正在使用Autofac运行Asp.net core 3.0 web API。其入口点如下所示:

using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;

namespace Myapp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            IHostBuilder builder = CreateHostBuilder(currentDirectory, args);
            using IHost host = builder.Build();
            host.Run();
        }

        public static IHostBuilder CreateHostBuilder(string currentDirectory, string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                       .ConfigureWebHostDefaults(webBuilder =>
                       {
                         webBuilder
                           .UseContentRoot(currentDirectory)
                           .UseIISIntegration()
                           .UseStartup<Startup>();
                       });
        }
    }
}
dotnet myapp.dll
并将其作为控制台应用程序启动,如下所示:

using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;

namespace Myapp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            IHostBuilder builder = CreateHostBuilder(currentDirectory, args);
            using IHost host = builder.Build();
            host.Run();
        }

        public static IHostBuilder CreateHostBuilder(string currentDirectory, string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                       .ConfigureWebHostDefaults(webBuilder =>
                       {
                         webBuilder
                           .UseContentRoot(currentDirectory)
                           .UseIISIntegration()
                           .UseStartup<Startup>();
                       });
        }
    }
}
dotnet myapp.dll
它运行正常

在IIS Express下从Visual Studio以调试模式启动它,它也可以正确运行(在https端口44393上)

然后我在IIS下配置了它。我将绑定设置为HTTP端口95和HTTPS端口96,并在web.config文件中启用标准输出日志。 但是,当尝试从浏览器访问应用程序时,调用失败,标准输出日志文件显示:

warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
      Using an in-memory repository. Keys will not be persisted to storage.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
      Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {c74e2418-52e2-492d-b49e-b28c053e4cc3} may be persisted to storage in unencrypted form.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
2019-12-02 14:14:20,820 INFO  (1) Microsoft.Hosting.Lifetime - Now listening on: http://localhost:5000
info2019-12-02 14:14:20,827 INFO  (1) Microsoft.Hosting.Lifetime - Application started. Press Ctrl+C to shut down.
这(特别是表示正在侦听端口5000的行)看起来与默认配置下显示的输出相同(即:未应用任何配置时)。因此,在我看来,所有提供给IIS的设置都被忽略或不被应用


错在哪里?如何解决此问题?

在Program.cs中,是否启用了IIS集成

      webBuilder.ConfigureKestrel()
          .UseIISIntegration() <<-----
          .UseSetting("detailedErrors", "true")
          .CaptureStartupErrors(true)
          .UseStartup<Startup>();
webBuilder.ConfigureKestrel()

.useisintegration()在Program.cs中,是否启用了IISIntegration

      webBuilder.ConfigureKestrel()
          .UseIISIntegration() <<-----
          .UseSetting("detailedErrors", "true")
          .CaptureStartupErrors(true)
          .UseStartup<Startup>();
webBuilder.ConfigureKestrel()

.UseIISIntegration()是的,它在方法CreateHostBuilderies中,它在方法CreateHostBuildery中,您在问题标题中特别提到“with Autofac”,并在此处标记
Autofac
-您是否做了一些事情来缩小与Autofac相关的范围?这听起来有点像一个笑话。重点是“某物”不起作用,但我不知道到底是什么。这可能是由于使用Autofac造成的错误,但我不确定。嗨,Starnuto,这是一个尽可能帮助我们的海报,将问题限制在允许任何人复制问题的最少代码量。您在问题标题中特别提到“使用Autofac”在这里标记
autofac
——您是否做了一些事情来缩小与autofac相关的范围?这听起来有点像一个笑话。重点是“某物”不起作用,但我不知道到底是什么。这可能是由于使用Autofac造成的错误,但我不确定。嗨,Starnuto,这是一个尽可能帮助我们的海报,将问题限制在允许任何人重现问题的最少代码量。