Welcome Guest Search | Active Topics | Sign In | Register

Log in for the user Options
Dave Covert
Posted: Tuesday, June 27, 2017 2:41:11 PM
Rank: Member
Groups: Member

Joined: 5/31/2011
Posts: 11
We are working on an application wherein we want to request a login page via https, fill in the username and password fields and submit the form back to the server without the view appearing in the browser.

After the submit, the next page will need to be shown to the user as it will either be a login error or the page we want to show.

How would we do this with EO.WebBrowser?

Dave
eo_support
Posted: Tuesday, June 27, 2017 3:58:22 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,070
Hi,

This is doable if your website uses persistent cookies for login. The basic steps are:

1. Use ThreadRunner to create an off-screen WebView. See here for more details:

https://www.essentialobjects.com/doc/webbrowser/start/webview_no_ui.aspx

2. Load the login page, fill in user name and password and submit the page. You will need to use JavaScript to do this. See here for more details:

https://www.essentialobjects.com/doc/webbrowser/advanced/js.aspx

3. If your website uses a persistent cookie for login, then as a response of the submit in step 2, the server would send an authentication cookie down to the WebView;

4. The WebView would save this cookie in the "cookie jar";

5. You can then use another visible WebView to load another page. The cookie received in step 3 will be automatically attached to the request and the server would consider it authenticated;

As you can see, step 3 and 4 are what enabled both WebView to share a single "session". If the server does not instruct the client to save cookie (similar to "Remember Me" option found in many login pages), then step 4 would not occur and step 5 would not succeed.

Hope this helps. Please let us know if you still have any more questions.

Thanks!
Dave Covert
Posted: Tuesday, June 27, 2017 5:17:44 PM
Rank: Member
Groups: Member

Joined: 5/31/2011
Posts: 11
Starting with Item 2 (I'll move it to a ThreadRunner later) I get the error 'The request was cancelled' when I attempt to log in. I tried this on multiple 3rd party web sites I have accounts on and get the same result. Here is what am trying:

Code: C#
private void WebView1_BeforeRequestLoad(object sender, BeforeRequestLoadEventArgs e)
{
    webView1.EvalScript(@"
        var u = document.getElementById('txtUsername');
	u.value = ""xxxx@xxxxx.com"";
	var p = document.getElementById('txtPassword');
	p.value = ""xxxxxxx"";
	var f = document.getElementById('login_form');
	f.submit();
    ");
}


Of course the exact IDs change depending on which web site I am trying to use.

Should I be doing this in another event handler? Do I need to set some property on the WebView?

Dave
eo_support
Posted: Tuesday, June 27, 2017 5:25:46 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,070
Why do you call EvalScript in BeforeRequestLoad event? You are using EvalScript to automate the page, so it should be obvious that you can only do that AFTER the login page has been fully loaded.
Dave Covert
Posted: Tuesday, June 27, 2017 10:38:55 PM
Rank: Member
Groups: Member

Joined: 5/31/2011
Posts: 11
I dunno... brain fart... long day I guess... Using LoadCompleted() worked as expected.

Dave
eo_support
Posted: Wednesday, June 28, 2017 8:04:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,070
Great. Glad to hear that it works for you!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.