mvc中测试网络

、//控制器层面

public string IsAnyNetworkAvailable()
{
try
{
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.OperationalStatus == OperationalStatus.Up &&
ni.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
ni.NetworkInterfaceType != NetworkInterfaceType.Tunnel)
{
IPInterfaceProperties iip = ni.GetIPProperties();
if (iip != null && iip.UnicastAddresses != null && iip.UnicastAddresses.Count > 0)
{
return "当前网络连接正常!";
}
}
}
return "当前网络不可用,无法连接到远程服务器!";
}
catch
{
return "当前网络不可用,无法连接到远程服务器!";
}
}

//页面ajax提交

IsAnyNetworkAvailable: function () {
$.ajax({
type: "post",
url: "/Order/IsAnyNetworkAvailable",
success: function (data) {
alert(data);
}
});
}

上一篇:Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+


下一篇:CSS 中 Font-Family 中英文对照表