首页 > 解决方案 > Asp.Net Core Web API 应用程序:如何更改监听地址?

问题描述

我编写了简单的 Asp.Net Core WebAPI 2.0 应用程序,它可以在我的本地机器上运行。但我想将它部署到服务器。所以,我做到了。

我的系统:

Ubuntu 16.04.
Asp.Net WebAPI 2.0 (and dotnet version 2.1.105)

但是,当应用程序启动时,它会写道:

Now listening on:http://localhost:53115

当我尝试从中获取值时:

  http://id_address:53115/api/values

我无法得到回应。在邮递员中:

 Could not get any response
 There was an error connecting to 
 http://id_address:53115/api/values.
 Why this might have happened:
 The server couldn't send a response:
 Ensure that the backend is working properly
 Self-signed SSL certificates are being blocked:
 Fix this by turning off 'SSL certificate verification' in Settings > General
 Proxy configured incorrectly
 Ensure that proxy is configured correctly in Settings > Proxy
 Request timeout:
 Change request timeout in Settings > General

我该做什么?你能告诉我如何解决这个问题吗?

我不知道从哪里开始寻找。

谢谢!

标签: ubuntuasp.net-coreasp.net-core-2.0asp.net-core-webapikestrel

解决方案


我正在使用 .NETCore 2.1 prev,所以我自己无法测试它,但如果我相信https://www.billbogaiv.com/posts/setting-aspnet-host-address-in-net-core -2,添加.UseUrls(urls: "http://*:5000")可能会指示 Kestrel 侦听端口 5000 而不仅仅是在本地主机上,因此它也应该在远程服务器上工作。

其他可能的解决方案,UseKestrel(..) https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore -2.1&tabs=aspnetcore2x使用IPAddress.Any而不是Loopback.


推荐阅读