Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从远程机器访问后端API_C#_Rest_Api_Asp.net Core - Fatal编程技术网

C# 如何从远程机器访问后端API

C# 如何从远程机器访问后端API,c#,rest,api,asp.net-core,C#,Rest,Api,Asp.net Core,当我使用以下launchSettings.json运行我的应用程序时,我正试图从具有以下ip地址(例如:192.168.1.80)的机器上获得对使用asp.net内核编写并在具有以下ip地址(例如:192.168.1.71)的机器中注册的后端API的访问(我的意思是发布、获取…): { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iis": {

当我使用以下launchSettings.json运行我的应用程序时,我正试图从具有以下ip地址(例如:192.168.1.80)的机器上获得对使用asp.net内核编写并在具有以下ip地址(例如:192.168.1.71)的机器中注册的后端API的访问(我的意思是发布、获取…):

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost/ServerMonitoringApi",
      "sslPort": 0
    },
    "iisExpress": {
      "applicationUrl": "http://localhost:9999",
      "sslPort": 0
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/Alerting",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ServerMonitoringApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/Alerting",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:9999;http://localhost:5000"
    }
  }
}
如果我呆在同一台机器上,我可以使用它,例如:,但是当我试图从我使用的远程机器获取数据时,它对我不起作用,我需要配置什么吗?或允许访问我的端口(9999)。
我是一个新手be gentel,谢谢你的帮助:)

Program.cs
中构建
WebHost
时,你需要指定更多的URL,否则Kestrel不会在localhost之外监听

var host=WebHost.CreateDefaultBuilder(args)
.useURL(“http://....“”//使用服务器名称或IP的服务器的url
.UseStartup()
.Build();

当然,在投入生产时不要忘记删除该行。

只是澄清一下,它们是在同一个网络中,还是在非现场托管API的计算机上?它们在同一个网络和同一个集群中。这样问题就更容易了,您的ASP.NET/IIS没有监听计算机的IP地址,而是监听
localhost
,因此只有尝试连接到
localhost
的连接才会被接受。您可以添加服务器所在位置的应用程序URL(在
Program.cs
中的代码中或在您的配置中),并且服务器应该可以工作。注意:绑定到
localhost
将不接受远程连接,但绑定到本地IP将接受远程连接和转到
localhost
的连接我按照@bmartins所说的那样做了,但我没有为自己工作,可能我遗漏了一些东西我的错误,我写得太快了。您应该输入服务器的url,如
http://:5000
http://:5000
如果您的应用程序面向kestrel,那么我相信您可以绑定到
0.0.0
,而不必显式地指定私有IP地址(可能会被DHCP重新分配)。如果它面向IIS,那就不同了。我写了这样一篇文章:。
ConfigureWebHostDefaults(webBuilder=>{webBuilder.UseUrls(“http://192.168.1.80:9999)。UseStartup();}),但它仍然不起作用:/I没有工作,它说Iit不能得到任何结果(顺便说一句,我使用邮递员进行测试)