拓冰建站拓冰建站
首页 / 资讯中心 / 正文

asp.net core发布配置端口号,支持linux

方式一修改配置文件 appsettings.json找到文件 appsettings.json添加如下节点配置在linux环境需要设置0.0.0.0才可以正常代表本机然后被其他机器访问此处设置端口8000Kestrel:{Endpoints:{Http:{Url:http://0.0.0.0:8000}}}或者,Kestrel:{Endpoints:{Http:{//0.0.0.0或* 有效用于linux、windows //Url:http://0.0.0.0:8000Url:http://*:8000//支持局域网ip访问}}}appsettings.json 完整代码参考{Logging:{LogLevel:{Default:Information,Microsoft.AspNetCore:Warning}},AllowedHosts:*,Kestrel:{Endpoints:{Http:{//0.0.0.0或* 有效用于linux、windows //Url:http://0.0.0.0:8000Url:http://*:8000}}}}方式二代码添加端口varbuilderWebApplication.CreateBuilder(args);builder.WebHost.ConfigureKestrel((context,serverOptions){serverOptions.Listen(IPAddress.Loopback,5900);serverOptions.Listen(IPAddress.Loopback,5901,listenOptions{listenOptions.UseHttps(testCert.pfx,testPassword);});});微软帮助文档https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/servers/kestrel/endpoints?viewaspnetcore-9.0#specify-ports-only
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门