Welcome Guest Search | Active Topics | Sign In | Register

[EO.WebBrowser][17.1.65.0] CertificateError event pass everything Options
Daniel
Posted: Thursday, June 1, 2017 6:04:08 AM
Rank: Member
Groups: Member

Joined: 1/25/2017
Posts: 18
Hi,
I've added to local IIS https binding and after this I have to handle CertificateError event.
I want to allow EO.WebBrowser.ErrorCode.CertificateCommonNameInvalid and block everything else.
In my scenario event is fired two times. I get errors: CertificateCommonNameInvalid and CertificateAuthorityInvalid.
My code:
Quote:
private void webView1_CertificateError(object sender, EO.WebBrowser.CertificateErrorEventArgs e)
{
switch (e.ErrorCode)
{
case EO.WebBrowser.ErrorCode.CertificateCommonNameInvalid:
e.Continue();
break;
default:
webView1.LoadHtml(string.Format("<html><body><h2>Unable to open site: {0}</h2></body></html>", e.ErrorCode.ToString()));
break;
}
}

Because of "default" page is not showing but when I remove it then page is opened normally. Why? Should second error prevent loading?
eo_support
Posted: Thursday, June 1, 2017 12:46:00 PM
Rank: Administration
Groups: Administration

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

Please try to display the error message in your WebView.LoadFailed event handler and see if that works. The reason is you should wait until the first load to finish (fail) before you try to display the error message.

When you handle WebView.LoadFailed event, set e.ErrorMessage in your event handler. Do not call webView.LoadHtml to display the error message.

Thanks!
Daniel
Posted: Friday, June 2, 2017 2:51:26 AM
Rank: Member
Groups: Member

Joined: 1/25/2017
Posts: 18
Hi,

Ok, Error message was displayed in wrong place. I fixed it and leave default message.

Anyway something is wrong...
When I leave empty body in WebView.CertificateError then WebView.LoadFailed is fired, message is shown etc...
My new code:
Quote:
private void webView1_CertificateError(object sender, EO.WebBrowser.CertificateErrorEventArgs e)
{
switch (e.ErrorCode)
{
case EO.WebBrowser.ErrorCode.CertificateCommonNameInvalid:
e.Continue();
break;
}
}
private void webView1_LoadFailed(object sender, EO.WebBrowser.LoadFailedEventArgs e)
{
e.UseDefaultMessage();
}

I want to ignore CertificateCommonNameInvalid only. I didn't ignore error CertificateAuthorityInvalid.
After this WebView.LoadFailed wasn't fired and page was opened normally. One error stay active so something is wrong.

It is self-signed certificate generated in IIS but I'm using 'localhost' and it generates this scenario.
I'm also connected to WinForm event ServicePointManager.ServerCertificateValidationCallback and I don't have this second error. Browsers are more sensitive probably.
eo_support
Posted: Friday, June 2, 2017 9:04:51 AM
Rank: Administration
Groups: Administration

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

This has to do with how Chromium engine works with certificate. A more meaningful translation of CertificateError event and e.Continue is:

CertificateError = Chrome asks the user "there is a problem with the server's certificate, do you still want to trust this certificate?"
e.Continue = User says "Yes, I would trust this certificate for this host from now on";

As a result, once you call e.Continue, it won't alert you other errors for this certificate on this host.

ServicePointManager.ServerCertificateValidationCallback is unrelated to this. That affects the behavior of other .NET classes (such as WebRequest), it does not affect the underlying Chromium browser engine used by EO.WebBrowser.

Thanks!


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.