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?
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).
In the Navigated event arguments, you can access the WebResponse, so you can access the HTTP response code.
Related
I have a WPF application where I use CefSharp Browser control to render web pages. I need to be able to perform an HttpPost and open the uri. I looked through CefSharp documentation and haven't found any concrete examples to achieve this functionality but I'm sure this may be a feature that is part of the CefSharp component. Any pointers to how to achieve this would be quite helpful.
Thanks
Are you getting a Url back from your Http Post or some HtmlContent ?
The HttpPost either way has nothing to do with the Web Browser Control.
You can make an Http Post outside of the control, which in turn would return you the html content, and you would use CefSharp to display the content returned using the LoadHtml function, or if you are getting a Url back from your post, then you just need to set the Url of your webbrowser wpf control to the Url returned by your Http Post.
I have a WPF application with a WebBrowser control inside.
When I navigate to a website, I would like to know if the page is online or not. I the page is not accessible, I would like to navigate to a local html error page...
How can I do it ?
The first solution I found is to do a WebRequest before navigating, but it require a additional website call... I would like to find an other solution.
I wanted to get the HTTP Status code of the page in the "navigated" event of the WebBrowser, but I found here that it's not possible qith a WebBrowser control because the WebResponse is always null...
Is there an other solution?
This seems a common question, I added a solution here using the .Net NavigationService. Alternatives are also discussed.
I'm using Frame control to display the webpage in wpf app but it throws WebException(Can't locate the remote server) if there is no internet connection.
How can I handle the WebException?
IIRC, the Frame control actually hosts an ActiveX control for the web browsing. When you set the Source property or call the Navigate method, it will asynchonously attempt to navigate the URI.
According to this MSDN post, you'll need to register to handle this asynchronous exception on the Dispatcher.UnhandledException event.
I am trying to implement a simple Facebook login flow using WPF. It turns out that I need to use some sort of embedded browser within the application if the application is a desktop application. Therefore I am using WebBrowser control, but I can't seem to correctly detect the redirecting URL.
Once I load the web page for facebook login, and after login, the browser redirects to a page of the form
https://www.facebook.com/connect/login_success.html#access_token=....
But if I look at the URI source, it only shows up to login_success.html and is cutting off whatever is after the # sign. I need this information for further processing, so I was wondering if anyone could advise on retrieving that access token using WebBrowser (or any other way) in WPF. Thanks!
I was having the saving problem with the WPF Sample in the SDK today. I figured it was a problem with the WPF Webbrowser control (like you had infered). So I used the windows.forms.webbrowser instead of the WPF webcontrol. It is a simple fix.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
_webBrowser = new System.Windows.Forms.WebBrowser();
host.Child = _webBrowser;
this.grid1.Children.Add(host);
_webBrowser.Navigated += new WebBrowserNavigatedEventHandler(webBrowser_Navigated);
_webBrowser.Navigate(_navigateUrl.AbsoluteUri);
I have a WPF webbrowser control which navigates the user to a registration site. After the user registers, a collection of headers are sent back alongwith the "finished registration" page.
I have tried the Navigated event, and tried accessing WebResponse property in the event arguments but it's always null.
Is there any other way to access the headers sent?
After quite a lot of reading, I figured out that WPF web browser actually wraps around the WinForm web browser which inturn wraps around a COM dll (which is even used by Internet Explorer).
Now this COM dll provides a lot of interfaces which are not exposed by any of the wrapper controls. So those who need more control need to implement these interfaces.
I found a browser which implements a lot of these interfaces and neatly provides a lot functionality. Used it and it's working fine. http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
It talks about implemnting a PassthroughAPP package to get the response headers.
I dont think you can access headers like that, best thing to do is, either use Hidden Fields of the form or you can pass on your cookie ASP.NET_SessionID from your finished page to your WPF app, and inside WPF app you can make custom request to your url with same ASP.NET_SessionID cookie where you will continue same session and you will be able to query responses you desire throught WebResponse.