我在Net Core Web API控制器中有一个非常简单的ping端点。它在本地工作正常。
但在已发布的 Azure 应用程序上,当我访问该端点时,它返回 500 状态代码表示内部服务器错误。
我尝试添加一些 NuGet 包,使用异步,但结果总是相同 - 在本地工作正常,但发布后不行。
我还尝试检查 Azure 门户,也许他们的服务器会阻止 ping?
编辑:
从 Azure 门户应用服务诊断报告中:
[HttpGet("ping")]
public IActionResult Ping()
{
string host = "www.google.com";
Ping servicePing = new Ping();
var reply = servicePing.Send(host);
return Ok($"{reply.Status}");
}
但在已发布的 Azure 应用程序上,当我访问该端点时,它返回 500 状态代码表示内部服务器错误。
我尝试添加一些 NuGet 包,使用异步,但结果总是相同 - 在本地工作正常,但发布后不行。
我还尝试检查 Azure 门户,也许他们的服务器会阻止 ping?
编辑:
从 Azure 门户应用服务诊断报告中:
at System.Net.NetworkInformation.Ping.InitialiseIcmpHandle
at System.Net.NetworkInformation.Ping.DoSendPingCore
at System.Net.NetworkInformation.Ping.GetAddressAndSend
at System.Net.NetworkInformation.Ping.GetAddressAndSend
at System.Net.NetworkInformation.Ping.Send
at TestApi.Controllers.WeatherForecastController.Ping
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync
编辑2:
我在Kudos中的调试控制台中检查了eventlog.xml文件,以查找异常。 (如果有更好的方法来检查服务器异常,请告诉我。)
这是实际的异常:
System.Net.NetworkInformation.PingException: An exception occurred during a Ping request.
---> System.ComponentModel.Win32Exception (5): Access is denied.
at System.Net.NetworkInformation.Ping.InitialiseIcmpHandle()
at System.Net.NetworkInformation.Ping.DoSendPingCore(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options, Boolean isAsync)
at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
--- End of inner exception stack trace ---
at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress)
at TestApi.Controllers.WeatherForecastController.Ping() in C:\Users\Dellas\source\repos\TestApi\TestApi\Controllers\WeatherForecastController.cs:line 48
这里有什么解决方法?Azure真的会阻止ping吗?