首页 > 解决方案 > 红隼定制

问题描述

UseKestrel尝试使用ASP.NET Core 2.2(在 Windows 10 上运行)中的中间件自定义 Kestrel 时,我无法运行我的网站。

public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
    return new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
            config.SetBasePath(env.ContentRootPath);
            config.AddInMemoryCollection(new[]
                   {
                             new KeyValuePair<string,string>("the-key", "the-value")
                   })
                   .AddJsonFile("appsettings.json", reloadOnChange: true, optional: false)
                   .AddJsonFile($"appsettings.{env}.json", optional: true)
                   .AddEnvironmentVariables();
        })
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddDebug();
            logging.AddConsole();
        })
        .UseIISIntegration()
        .UseDefaultServiceProvider((context, options) =>
        {
            options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
        })
        .UseStartup<Startup>();
}

我没有收到错误消息,但我的网站无法加载。

标签: c#asp.net-core

解决方案


你能试试这个,看看会发生什么 -

        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            return WebHost.CreateDefaultBuilder(args)                    
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseKestrel(options =>
              {
                  options.Listen(IPAddress.Parse(0.0.0.0), Convert.ToInt32(5000));
              })
                .UseUrls("0.0.0.0:5000")
                .UseStartup<Startup>();
        }

推荐阅读