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.
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 am having a my problem is I can not redirect my page in silverlight like most of people who are not familiar with this technology .
I design a login page first and if password is correct I want it to direct to MainPage.xaml
as you can see I tried methods which are commented already it did not work . I searched in this web page there are some posts about this problem but I could not solve please help me .
when i try that one;
Uri target = new Uri("MainPage",UriKind.Relative);
NavigationService.Navigate(target);
error message : Object reference not set to an instance of an object.
actually we found a solution with my friend ;
instead of directing a web page , when code goes into if block we are changing the content of page with {this.Content = new MainPage() ; } method and it is working .But System.Windows.Browser.HtmlPage.Window.Navigate(target) this one is directing us same login page or pages like www.---.com outside normal html pages .
Normally you need to use the NavigationService to do this:
NavigationService.Navigate(new Uri("/MainPage", UriKind.Relative));
The NavigationService is a property on the Page object so it will be available in the Login code-behind.
However, after you mentioned that you've "already done this" I realized the issue. Silverlight Navigation uses a Frame control. This Frame control lives in MainPage.xaml for the default project. So you're not navigating inside the frame, but you want to change the entire screen to a different one and do so without the Navigation services built into Silverlight.
I'd suggest you either (a) have the Login run as a page inside of the Frame on MainPage (you can load or unload the links on the top based on if the user is authenticated) or (b) don't use the Navigation for the remainder of the application and use a framework like Caliburn.Micro to handle all the Navigation between views.
This might not be possible but I thought I'd check with everyone.
Is it possible to load a WebBrowserTask on WP7 but to have the url entry box collapsed? I'd also like to set IsHitVisble to false?
The reason I want to do this is to load a url (through databinding) but ensure that the user can't browse to other links on the page. I also need to keep the phones share control in the tool bar so I can't just use a webbrowser control and set the source to the url.
Does anyone have any ideas?
Not possible. You can use a WebBrowserControl inside your own app, but it's not recommended.
Basically such odd/weird limitations as this, don't belong in any modern day craftsmanship. And thus why it isn't a possibility (thanks Microsoft!)
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 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.