检测是否离线 - 在 C# WebBrowser 组件中?
我们正在开发一个封装的 WebBrowser 组件。如果用户在线,我们希望显示一个页面(例如 oursite.com/thispage.html),如果用户离线,我们希望显示另一页面(例如 C:\somewhere\thispage_offline.html)。我能够正确显示两个页面,但我的问题是检测在线/离线状态。
我试过 WebBrowser.IsOffline;然而,似乎只转发离线模式状态,而不转发计算机是否真正能够访问互联网。
有没有办法从 WebBrowser 组件中检测到这一点?有办法吗?
感谢您的帮助!
We're working on a wrapped WebBrowser component. We'd like to display one page (e.g. oursite.com/thispage.html) if the user is online and another page (e.g. C:\somewhere\thispage_offline.html) if the user is offline. I'm able to to properly display both pages, but my issue is detecting the online/offline status.
I tried
WebBrowser.IsOffline; however it seems that only relays the Offline Mode status, not whether or not the computer is actually able to reach the internet.
Is there a way to detect this from the WebBrowser component? Is there a way at all?
Thanks for all your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查互联网连接的最简单方法是 ping 您的服务器。
尝试此代码:
或者,您可以尝试使用
WebRequest
class 向您网站上的简单页面发送请求并查看是否成功。这是一个更好的选择,因为它还可以确保 IIS(或 Apache)在服务器上运行。The simplest way to check for internet connectivity is to ping your server.
Try this code:
Alternatively, you can try using the
WebRequest
class to send a request to a simple page on your site and see whether it succeeds. This is a better option because it will also make sure that IIS (or Apache) is running on the server.如果您只是使用 Ping 类会怎么样?查看该网站是否可用?
What if you just used the Ping class to see if the site is available?