本文介绍了Asp.Net Core Web API应用程序:如何更改监听地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I write simple Asp.Net Core WebAPI 2.0 application, it works on my local machine.But i want to deploy it to server.So, i do it.

我的系统:

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

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

But, when app starts it writes:

Now listening on:http://localhost:53115

当我尝试从中获取价值时:

When i try to get values from it:

  http://id_address:53115/api/values

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

And i can not get response.In Postman:

 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

我该怎么办?你能告诉我如何解决吗?

What i should do? Can you tell me how to fix that?

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

I do not know where to start looking for.

谢谢!

推荐答案

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

I'm using .NETCore 2.1 prev, so I haven't been able to test it myself but if I believe that https://www.billbogaiv.com/posts/setting-aspnet-host-address-in-net-core-2, adding .UseUrls(urls: "http://*:5000") might be instructing Kestrel to listen to port 5000 and not only on localhost, so it should work also on a remote server.

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

Other possible solution, UseKestrel(..) https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1&tabs=aspnetcore2x using IPAddress.Any instead of Loopback.

这篇关于Asp.Net Core Web API应用程序:如何更改监听地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 09:55