简体   繁体   English

如何覆盖 Kestrel 中的默认端口

[英]How to override default ports in Kestrel

i have simple method我有简单的方法

public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
        }

and i am write appsettings:我正在写应用程序设置:

"Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http1AndHttp2"
    },
    "Endpoints": {
      "Api": {
        "Url": "https://+:5005",
        "Protocols": "Http1AndHttp2"
      },
      "Grpc": {
        "Url": "http://+:5006",
        "Protocols": "Http2"
      }
    }
  }

but when i start app, i see warning:但是当我启动应用程序时,我看到警告:

"Microsoft.AspNetCore.Server.Kestrel", "message": "Overriding address(es) 'https:\/\/localhost:5000, https:\/\/localhost:5001'. Binding to endpoints defined in UseKestrel() instead.", "addresses": "https:\/\/localhost:5000, https:\/\/localhost:5001
", "methodName": "UseKestrel()" }

and app start at standard port 5000, but i expect on port 5005和应用程序从标准端口 5000 开始,但我希望在端口 5005

Why Kestrel changes the start port and how to make the application start on a given https://localhost:5005/api-docs/someService (i am use swagger)为什么 Kestrel 更改启动端口以及如何使应用程序在给定的 https://localhost:5005/api-docs/someService 上启动(我使用 swagger)

As said on your application startup just do it in UseKestrel()正如您在应用程序启动时所说,只需在UseKestrel()中执行即可

return Host.CreateDefaultBuilder(args)
       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
       .ConfigureWebHostDefaults(builder => builder.UseKestrel(x=>x.Listen(IPAddress.Any, 5005)).UseStartup<Startup>());

i am find that i need feel launchSettings.json with我发现我需要使用 launchSettings.json

"launchUrl": "https://localhost:5005/api-docs/SomeService"
  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置 Kestrel 以使用定义的端口范围中的随机动态端口 - How do you configure Kestrel to use a random dynamic port from a defined range of ports 在服务结构的不同端口上运行的多个红隼无状态服务实例 - Multiple kestrel stateless service instances running on different ports in service fabric 使用 Kestrel 仅针对特定端口进行 HTTPS 重定向(侦听混合端口) - HTTPS redirection for specific port only (listening on mixed ports) with Kestrel 如何覆盖默认的 JsonConverter(在属性中指定) - How to Override a Default JsonConverter (specified in an attribute) 如何覆盖 Wix 中的默认 MSIFASTINSTALL 值? - How to override the default MSIFASTINSTALL value in Wix? 如何覆盖默认窗口关闭操作? - How to override default window close operation? 自定义控件:如何覆盖默认属性? - Custom control: How to override default properties? 如何使用默认覆盖的异步处理和等待 - How to handle async & await with default override's 如何覆盖Owin中的默认未处理异常输出? - How to override default unhandled exception output in Owin? 如何在Silverlight中覆盖键盘键的默认行为 - How to Override the default behaviour of keyboard keys in Silverlight
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM