调用系统API判断网络连接状态 判断是否连接到网络using System.Runtime.InteropServices; //调用API用的命名空间 private void Page_Load(object sender, System.EventArgs e) { if(!IsConnected()) { Response.Write("没有连接到网络!"); } else { Response.Write("已连接到网络!"); } } //检测网络连接是否连接到Internet [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); public bool IsConnected() { int connectionDescription = 0; return InternetGetConnectedState(out connectionDescription, 0); }