小编col*_*ins的帖子

在 Azure 应用服务应用程序中向本地主机发出请求

我有一个连续的网络作业,用于侦听包含诊断信息的请求。

为了测试连接性,我尝试在我的 Web 作业中进行健康检查,但无法根据 azure 应用服务文档向 localhost 发出请求。

下面的代码是我用来验证我可以从我部署的应用程序连接的代码:

    var uri = new Uri("http://localhost:8989/ping");
    var response = await client.GetAsync(uri);
Run Code Online (Sandbox Code Playgroud)

我得到这个例外:

System.Net.Http.HttpRequestException: An error occurred while sending the request. 
---> System.Net.WebException: Unable to connect to the remote server 
---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:8989
Run Code Online (Sandbox Code Playgroud)

Web 作业是通过 Kudu (SCM) 通过站点扩展安装脚本安装的,这意味着 Web 作业最终是 Kudu (SCM) 的子进程。启动时的 Web 作业应用程序将自身绑定到端口 8989。在 Windows 上本地启动应用程序,我可以毫无问题地进行健康检查。

azure 应用服务文档说,除非同一沙箱中的应用程序绑定到端口,否则对 localhost 的请求将失败(https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#local-address-请求)。

azure 应用服务文档指出 Kudu …

.net http azure azure-app-service-envrmnt azure-web-app-service

8
推荐指数
1
解决办法
2527
查看次数