gpt4 book ai didi

c# - 如何更改 Asp.Net 核心应用程序的端口号?

转载 作者:行者123 更新时间:2023-12-02 19:52:13 24 4
gpt4 key购买 nike

我在 project.json 中添加了以下部分.

  "commands": {
"run": "run server.urls=http://localhost:8082",
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:8082",
"weblistener": "Microsoft.AspNet.Hosting --server WebListener --server.urls http://localhost:8082"
},

但是,当使用 dotnet myapp.dll 运行它时,它仍然显示“现在正在监听: http://localhost:5000” ?

顺便说一句,其他机器的客户端可以访问该服务吗?

最佳答案

是的,如果您绑定(bind)任何外部 IP 地址,这将可以从其他机器访问。例如绑定(bind)到 http://*:80 .注意绑定(bind)到 http://localhost:80只会在 127.0.0.1 接口(interface)上绑定(bind),因此无法从其他机器访问。
Visual Studio 正在覆盖您的端口。您可以更改 VS 端口编辑此文件 Properties\launchSettings.json或者通过代码设置它:

        var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://localhost:80") // <-----
.Build();

host.Run();
提供使用外部配置文件的分步指南 here .

关于c# - 如何更改 Asp.Net 核心应用程序的端口号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59955540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com