i made a winForms application that uses web browser control that enables the user to sign in with his google or facebook account then after getting the information or any error or exception the form which contains the web browser closes and will return back to the main form, i do the following, prepare the request, navigate() using that request then catch the response with the event Navigated.
in the code all is working fine, but when i build as Release and install the application the Navigated event is never fired up, which is really weird since nothing in my code is in debug condition, any ideas how to solve this issue??
the code at form's load event is:
private void GoogleLogin_Load(object sender, EventArgs e)
{
AuthHelper authHelper = new AuthHelper();
Uri loginURI = authHelper.GetGoogleAuthURI(_appID, redirectURI);
GoogleLoginControl.Navigate(loginURI);
}
the code at the web browser control at Navigated event
private void GoogleLoginControl_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
CoreStaticMembers.ologger.LogToFile("Navigated event with the absolute URL "+ e.Url.AbsoluteUri );
MessageBox.Show("Navigated event is fired");
///used if parameters are empty so ignore the following messages
bool ignore = false;
string code = null;
if (e.Url.AbsolutePath.Equals("/connect/login_success.html"))
{
AuthHelper authHelper = new AuthHelper();
//NameValueCollection parameters = HttpUtility.ParseQueryString(e.Url.Query);
try
{
NameValueCollection parameters = HttpUtility.ParseQueryString(e.Url.Query);
if (parameters != null)
{
string jsonResponse = null;
and after that i continue with normal authentication and data acquiring, keep in mind that this issue only appears when i build as Release then install the application, also the Navigating even is fired for the web browser control, so does the Load event for the parent form
Thanks in advance
UPDATE
by the way i also tried to Navigate with the required URL when i initialize the form by calling Initialize function inside the form's constructor, but the same problem appeared,
i found out that this problem is related to a compatibility issue related to a DLL file, particularly "Newtonsoft" DLL.
Related
The steps to reproduce this are very simple. Just download the latest version of CefSharp.WinForms (57.0.0) with nuget, then add a button and this code to a form:
public partial class Form1 : Form
{
ChromiumWebBrowser WebBrowser;
public Form1()
{
InitializeComponent();
WebBrowser = new ChromiumWebBrowser("about:blank");
panel1.Controls.Add(WebBrowser);
WebBrowser.Dock = DockStyle.Fill;
}
private void testButton_Click(object sender, EventArgs e)
{
MessageBox.Show(WebBrowser.CanExecuteJavascriptInMainFrame.ToString());
}
}
Then run the application, wait a few seconds to make sure "about:blank" has loaded and press the testButton. The message box will show False. In fact, if I attempt to use EvaluateScriptAsync I will get an exception telling me the context has not been created.
One way to solve this is to call ShowDevTools, which seems to somehow force a context to be created. Another solution is to navigate to a non local page such as Google. In this case, even if I go back to "about:blank" I'll be able to run scripts. I tried using a custom scheme registered with CefSettings.RegisterScheme, but navigating to my custom page still does not create a context (I tried passing "about:blank" to the constructor and then navigating to my custom scheme and the other way around too and none worked).
So, is it possible to have CefSharp create a context without having to navigate to a non-local page or to show DevTools?
You will have to use the following functions:
WebBrowser.GetMainFrame().ExecuteJavaScriptAsync(string code);
WebBrowser.GetMainFrame().EvaluateScriptAsync(string code);
This bypasses the regular check for V8Context.
More information from CefSharp, found here:
For frames that do not contain JavaScript then no V8Context will be created. Executing a script once the frame has loaded it's possible to create a V8Context.
You can use browser.GetMainFrame().ExecuteJavaScriptAsync(script) or browser.GetMainFrame().EvaluateScriptAsync to bypass these checks.
I have simple windows form application with a single ActiveX control in it. That is Microsoft RDP Client Control - version 10.
Here is Constructor for the form
public ConnectionWindow()
{
InitializeComponent();
MsRdpClient.Server = "server";
MsRdpClient.UserName = "Administrator";
MsRdpClient.Domain = "domain.com";
IMsTscNonScriptable secured = (IMsTscNonScriptable)MsRdpClient.GetOcx();
secured.ClearTextPassword = "password";
MsRdpClient.Connect();
}
The only thing i get from this is "Internal error has occurred" from disconnected arguments when subscribing to MsRdpClient_OnDisconnected event:
private void MsRdpClient_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e)
{
var rdp = sender as AxMsRdpClient9;
var errorString = rdp.GetErrorDescription((uint)e.discReason, (uint)rdp.ExtendedDisconnectReason);
Console.WriteLine("Disconnected event reason: " + errorString);
}
I tried subscribing to most of the events in the control, but the only other thing i get is MsRdpClient_OnAuthenticationWarningDisplayed event invoke, but it doesn't give me any information.
P.S. the control itself just gives blank view.
When connecting to remtoe pc via mstsc everything is fine, credentials fit.
Anyone has any idea about this?
The application main entry point was a console application. For some weird reason RDP control needs a call Application.EnableVisualStyles() on main application entry point to work correctly.
I wrote a method to post to Twitter using webclient. Everything works fine when calling the method from a console app.
I migrated the method to Silverlight 4. Here is where the fun begins. After cleaning up the code, switching to an asynchronous method call, and getting rid of the red squiggled underlines, the code now runs inside my SL4 app. The tweets do not, however, actually post to my twitter page.
I wired up an event handler for the "_completed" event. It gets fired.
Also wired up an event handler for the "_uploadProgressChanged" event. It never gets fired. Could be upload is too quick?
Any suggestions for troubleshooting this?
Update #2-
Correction... the "_completed" event DOES NOT get fired. I also added Fiddler to the mix to watch the traffic. It does not appear the app is transmitting anything. Fiddler does show activity if I post to stackoverflow (so Fiddler is working).
public static void PostTwitterUpdate(string handle, string pwd, string tweet)
{
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential(handle, pwd);
Uri uriString = new Uri("http://twitter.com/statuses/update.xml", UriKind.Absolute);
try
{
// event handlers added tongiht for debugging...
webClient.UploadProgressChanged += webClient_UploadProgressChanged;
webClient.UploadStringCompleted += webClient_UploadStringCompleted;
webClient.UploadStringAsync(uriString, "It's just me testing...");
}
catch (Exception ex)
{
throw;
}
}
static void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
// breakpoint set here for debugging...
}
static void webClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
// breakpoint set here for debugging...
}
This only would work in an elevated trust Out-of-Browser application because the Twitter Cross Domain Policy File at http://twitter.com/crossdomain.xml does not permit the calls for web page based apps.
Michael
I'm new in Silverlight and i am doing some tests. With my current test I try to display in real time the current Clipboard content. But there is a weird behaviors with this code :
namespace SilverlightTest
{
public partial class MainPage : UserControl
{
private Timer _timer;
public MainPage()
{
InitializeComponent();
var dispatcher_timer = new DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 5)};
dispatcher_timer.Tick += new EventHandler(timer_Callback);
dispatcher_timer.Start();
}
private void timer_Callback(object state, EventArgs eventArgs)
{
current_clip_board.Content = Clipboard.GetText();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
current_clip_board.Content = Clipboard.GetText();
}
}
}
The button Event and the timer Event are suppose to do exactly the same action.
But it doesn't ! The Button works fine and set the clipboard text into the label but the timer throw an exception :
Clipboard access is not allowed
The question is : why ? :)
Thanks.
PS : I would bet on a thread problem :p
Clipboard access, in a partial trust (in-browser) Silverlight application (the scenario you're likely referring to above), is restricted. The GetText property is accessible only in scenarios that the Silverlight runtime determines were initiated by the user. Your example is perfect -- by a button click for example. A dispatch timer however is not user initiated, so the property throws an exception (this is especially important within the context of a in-browser application, which could be a big security hole if you could create a Silverlight application that just ran silently in the browser, watching the user's clipboard updates without their knowledge).
See this clipboard documentation for more details.
Just trigger Clipboard.ContainsText() instead of Text. The method ContainsText is allowed!
Have you tried this:
private void timer_Callback(object state, EventArgs eventArgs)
{
Dispatcher.Invoke(new System.Threading.ThreadStart(delegate()
{
current_clip_board.Content = Clipboard.GetText();
}
}
edit
After a quick search, it appears that Clipboard is only available in response to a user action see here and here.
In partial trust (the default mode for
browser-hosted Silverlight-based
applications), Silverlight also
restricts clipboard access to its two
key APIs GetText and SetText. These
APIs can only be invoked from within a
context that is determined by the
Silverlight runtime to be in response
to a user-initiated action. For
example, clipboard access is valid
from within a handler for a Click or
KeyDown event. In contrast, clipboard
access is not valid from a handler for
Loaded or from a constructor, and
access attempts throw exceptions.
If your only option is to use a timer, then don't do it at all. The clipboad is a shared resource, and you're going to raise "cannot open clipboard" errors in other programs as they try to access the clipboard. i.e. user copies something from WinWord, WinWord tries to open the clipboard, but can't, because you've got it locked while you're examining it.
Hello this works for me but only in IE Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() => HtmlPage.Window.Eval("window.clipboardData.setData('Text','testtestest')"));
just use getData method
How can I solve this error?
"The requested resource is in use. (Exception from HRESULT: 0x800700AA)".
This appears while navigating to a different website using the WebBrowser control in C# .NET. Why?
The WebBrowser control is considered "in use" if either a navigation action is currently being processed, or any blocking dialog from the control is currently open (including context menu, Javascript alerts, NTLM login dialog, etc.). You can use the WebBrowser.IsBusy property to detect these states.
If due to a currently incomplete navigation action, you could try to stop the current navigation (if you indeed want to stop when the page is not completed loaded) or add the new navigation to a request queue and use a timer to wait until WebBrowser.IsBusy returns false.
If instead the busy state is due to one or more open blocking dialogs, you could do the same wait technique and perhaps Messagebox.Show() the user a message that pending navigation is delayed due to an open dialog window.
I had this same issue. Calling WebBrowser.Stop() did not help, and WebBrowser.IsBusy never became false.
It turns out that if the page creates any sort of dialog (alert() popups, javascript errors, NTLM login popups etc.) you can't navigate away from the page until the dialog is closed.
My solution was to prevent the dialogs from showing in the first place. Apparently preventing all of these popups is simple; just set
webBrowser.ScriptErrorsSuppressed = true;
bool go = false;
string SiteContent1 = string.Empty;
string SiteContent2 = string.Empty;
int index = 0;
WebBrowser wb = new WebBrowser();
void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
if (go)
{
SiteContent2 = wb.DocumentText;
// Code to compare to contents of the webbrowser
index++;
go = false;
steps = 1;
}
if (!go)
{
if (index >= TotalSiteCount)
{
Stop();
}
else if (steps == 1)
{
wb.Navigate(UrltocompareList[index].Url1);
}
else if (steps == 2)
{
SiteContent1 = wb.DocumentText;
wb.Navigate(UrltocompareList[index].Url2);
go = true;
}
steps++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
UrltocompareList is a collection of 2 sites to compare.
TotalSiteCount is the number of items in UrltocompareList.
The form for this inherit IOleClientSite to remove media such as images, videos and no active X download to have a faster rendering time in webbrowser control.
I use this method instead of system.net.webclient to get the html of a webpage then compare them.
I got this error when it hits the wb.Navigate method.
An issue I ran into when running specflow tests with watin in windows 10 is that win10 by default uses MS Edge, so I had never opened IE, and when watin started it IE was stuck on the prompt for using default settings. Selecting options, closing browser and running tests again worked for me.
Just something to watch
This can be solved pretty easily.
This error occurs when the browser commits an action while he's already performing an action.
For example, you are navigating to some website while you rightclick in the web browser.
To solve this, I did the follow:
//if my webbrowser isn't performing any actions
if(!myWebBrowser.IsBusy)
{
//Navigate
myWebBrowser.Navigate("http://www.google.com");
}
First Try
1- Please Check Navigate URL's (if you check, please check again compiled folder)
2- Delete WebBrowser Control and Add New
Me forget copy original file App.Path + "\error.html" and see this problem.
Guarantee Method
I Fix This Error in VB6
Add WebBrowserControl wb(0) (Name wb , Index=0)
And Before Ever Navigate
For i = 1 To wb.UBound
Unload wb(i)
Next
Load wb(1)
wb(0).Visible = False
wb(1).Visible = true
wb(1).Navigate URL