WPF WebBrowser events for HTTP errors?

人走茶凉 提交于 2019-12-24 00:06:55

问题


I have a WPF application and I'm using the WebBrowser control to display some content from a public website.

Sometimes in weird edge cases when the network connectivity is flakey, the web browser will show the "This program cannot display the webpage" error page. Is there some way to listen to the WebBrowser to detect when this occurs, so I can load a placeholder?


回答1:


You could try using the NavigationService from System.Windows.Controls.Frame as indicated in this MSDN forum post. The WebResponse will always be null for the WebBrowser control in WPF (as described in the post).




回答2:


In the Navigated event arguments, you can access the WebResponse, so you can access the HTTP response code.



来源:https://stackoverflow.com/questions/1473453/wpf-webbrowser-events-for-http-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!