Aleehome

Aleehome_Code

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);
}
});
}

 

posted on 2015-10-29 09:13  Aleehome  阅读(178)  评论(0编辑  收藏  举报

导航