Xamarin Forms WebView loading mixed content in Android
up vote
0
down vote
favorite
I have a Xamarin Forms WebView. The Source is a Webpage which contains mixed content (links to https and http resources). It loads in Xamarin Forms iOS without problems, however in Android it will not load, and I suspect that the problems is the mixed content.
How can I set MixedContentMode?
There is documentation at https://docs.microsoft.com/de-de/dotnet/api/xamarin.forms.platformconfiguration.androidspecific.webview.setmixedcontentmode?view=xamarin-forms
But I don't understand how to use that. Can someone give me an example?
Thanks a lot.
add a comment |
up vote
0
down vote
favorite
I have a Xamarin Forms WebView. The Source is a Webpage which contains mixed content (links to https and http resources). It loads in Xamarin Forms iOS without problems, however in Android it will not load, and I suspect that the problems is the mixed content.
How can I set MixedContentMode?
There is documentation at https://docs.microsoft.com/de-de/dotnet/api/xamarin.forms.platformconfiguration.androidspecific.webview.setmixedcontentmode?view=xamarin-forms
But I don't understand how to use that. Can someone give me an example?
Thanks a lot.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a Xamarin Forms WebView. The Source is a Webpage which contains mixed content (links to https and http resources). It loads in Xamarin Forms iOS without problems, however in Android it will not load, and I suspect that the problems is the mixed content.
How can I set MixedContentMode?
There is documentation at https://docs.microsoft.com/de-de/dotnet/api/xamarin.forms.platformconfiguration.androidspecific.webview.setmixedcontentmode?view=xamarin-forms
But I don't understand how to use that. Can someone give me an example?
Thanks a lot.
I have a Xamarin Forms WebView. The Source is a Webpage which contains mixed content (links to https and http resources). It loads in Xamarin Forms iOS without problems, however in Android it will not load, and I suspect that the problems is the mixed content.
How can I set MixedContentMode?
There is documentation at https://docs.microsoft.com/de-de/dotnet/api/xamarin.forms.platformconfiguration.androidspecific.webview.setmixedcontentmode?view=xamarin-forms
But I don't understand how to use that. Can someone give me an example?
Thanks a lot.
asked yesterday
mrd
1,83783871
1,83783871
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
It depends a little bit if you have defined your WebView in code or XAML.
If you defined it in code, make sure you have a reference to it by the variable name, for instance:
var myWebView = new WebView();
myWebView is what I am talking about in this case.
Then, include this using at the top of your class:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
Then add this line after you have initialized the WebView:
myWebView.On<Android>().SetMixedContentMode(MixedContentHandling.AlwaysAllow);
From XAML, add the right namespace to the root of your page, like this:
<ContentPage xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" ....>
Then, on your WebView, you can just add another attribute: <WebView ... android:WebView.MixedContentMode="AlwaysAllow" />
These are the so-called platform-specifics. You can set platform-specific properties directly from Xamarin.Forms shared code as opposed to having a custom renderer in place for one simple property.
Read more on it here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/ and consuming (this specific case, actually) here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#enabling-mixed-content-in-a-webview
A note on the actual thing you are setting here, in the example I simply set it to AlwaysAllow, ensure you know what each option does and set it to the most secure one. Here is a small explanation, taken from the Microsoft Docs:
AlwaysAllow– indicates that theWebViewwill allow an HTTPS origin to load content from an HTTP origin.
NeverAllow– indicates that theWebViewwill not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode– indicates that theWebViewwill attempt to be compatible with the approach of the latest device web browser. Some
HTTP content may be allowed to be loaded by an HTTPS origin and other
types of content will be blocked. The types of content that are
blocked or allowed may change with each operating system release.
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
|
show 3 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
It depends a little bit if you have defined your WebView in code or XAML.
If you defined it in code, make sure you have a reference to it by the variable name, for instance:
var myWebView = new WebView();
myWebView is what I am talking about in this case.
Then, include this using at the top of your class:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
Then add this line after you have initialized the WebView:
myWebView.On<Android>().SetMixedContentMode(MixedContentHandling.AlwaysAllow);
From XAML, add the right namespace to the root of your page, like this:
<ContentPage xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" ....>
Then, on your WebView, you can just add another attribute: <WebView ... android:WebView.MixedContentMode="AlwaysAllow" />
These are the so-called platform-specifics. You can set platform-specific properties directly from Xamarin.Forms shared code as opposed to having a custom renderer in place for one simple property.
Read more on it here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/ and consuming (this specific case, actually) here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#enabling-mixed-content-in-a-webview
A note on the actual thing you are setting here, in the example I simply set it to AlwaysAllow, ensure you know what each option does and set it to the most secure one. Here is a small explanation, taken from the Microsoft Docs:
AlwaysAllow– indicates that theWebViewwill allow an HTTPS origin to load content from an HTTP origin.
NeverAllow– indicates that theWebViewwill not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode– indicates that theWebViewwill attempt to be compatible with the approach of the latest device web browser. Some
HTTP content may be allowed to be loaded by an HTTPS origin and other
types of content will be blocked. The types of content that are
blocked or allowed may change with each operating system release.
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
|
show 3 more comments
up vote
1
down vote
It depends a little bit if you have defined your WebView in code or XAML.
If you defined it in code, make sure you have a reference to it by the variable name, for instance:
var myWebView = new WebView();
myWebView is what I am talking about in this case.
Then, include this using at the top of your class:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
Then add this line after you have initialized the WebView:
myWebView.On<Android>().SetMixedContentMode(MixedContentHandling.AlwaysAllow);
From XAML, add the right namespace to the root of your page, like this:
<ContentPage xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" ....>
Then, on your WebView, you can just add another attribute: <WebView ... android:WebView.MixedContentMode="AlwaysAllow" />
These are the so-called platform-specifics. You can set platform-specific properties directly from Xamarin.Forms shared code as opposed to having a custom renderer in place for one simple property.
Read more on it here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/ and consuming (this specific case, actually) here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#enabling-mixed-content-in-a-webview
A note on the actual thing you are setting here, in the example I simply set it to AlwaysAllow, ensure you know what each option does and set it to the most secure one. Here is a small explanation, taken from the Microsoft Docs:
AlwaysAllow– indicates that theWebViewwill allow an HTTPS origin to load content from an HTTP origin.
NeverAllow– indicates that theWebViewwill not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode– indicates that theWebViewwill attempt to be compatible with the approach of the latest device web browser. Some
HTTP content may be allowed to be loaded by an HTTPS origin and other
types of content will be blocked. The types of content that are
blocked or allowed may change with each operating system release.
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
|
show 3 more comments
up vote
1
down vote
up vote
1
down vote
It depends a little bit if you have defined your WebView in code or XAML.
If you defined it in code, make sure you have a reference to it by the variable name, for instance:
var myWebView = new WebView();
myWebView is what I am talking about in this case.
Then, include this using at the top of your class:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
Then add this line after you have initialized the WebView:
myWebView.On<Android>().SetMixedContentMode(MixedContentHandling.AlwaysAllow);
From XAML, add the right namespace to the root of your page, like this:
<ContentPage xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" ....>
Then, on your WebView, you can just add another attribute: <WebView ... android:WebView.MixedContentMode="AlwaysAllow" />
These are the so-called platform-specifics. You can set platform-specific properties directly from Xamarin.Forms shared code as opposed to having a custom renderer in place for one simple property.
Read more on it here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/ and consuming (this specific case, actually) here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#enabling-mixed-content-in-a-webview
A note on the actual thing you are setting here, in the example I simply set it to AlwaysAllow, ensure you know what each option does and set it to the most secure one. Here is a small explanation, taken from the Microsoft Docs:
AlwaysAllow– indicates that theWebViewwill allow an HTTPS origin to load content from an HTTP origin.
NeverAllow– indicates that theWebViewwill not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode– indicates that theWebViewwill attempt to be compatible with the approach of the latest device web browser. Some
HTTP content may be allowed to be loaded by an HTTPS origin and other
types of content will be blocked. The types of content that are
blocked or allowed may change with each operating system release.
It depends a little bit if you have defined your WebView in code or XAML.
If you defined it in code, make sure you have a reference to it by the variable name, for instance:
var myWebView = new WebView();
myWebView is what I am talking about in this case.
Then, include this using at the top of your class:
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
Then add this line after you have initialized the WebView:
myWebView.On<Android>().SetMixedContentMode(MixedContentHandling.AlwaysAllow);
From XAML, add the right namespace to the root of your page, like this:
<ContentPage xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" ....>
Then, on your WebView, you can just add another attribute: <WebView ... android:WebView.MixedContentMode="AlwaysAllow" />
These are the so-called platform-specifics. You can set platform-specific properties directly from Xamarin.Forms shared code as opposed to having a custom renderer in place for one simple property.
Read more on it here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/ and consuming (this specific case, actually) here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android#enabling-mixed-content-in-a-webview
A note on the actual thing you are setting here, in the example I simply set it to AlwaysAllow, ensure you know what each option does and set it to the most secure one. Here is a small explanation, taken from the Microsoft Docs:
AlwaysAllow– indicates that theWebViewwill allow an HTTPS origin to load content from an HTTP origin.
NeverAllow– indicates that theWebViewwill not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode– indicates that theWebViewwill attempt to be compatible with the approach of the latest device web browser. Some
HTTP content may be allowed to be loaded by an HTTPS origin and other
types of content will be blocked. The types of content that are
blocked or allowed may change with each operating system release.
edited yesterday
answered yesterday
Gerald Versluis
15.5k43155
15.5k43155
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
|
show 3 more comments
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
Application Output: [WebViewFactory] Loading com.android.chrome version 70.0.3538.80 (code 353808052) [zygote64] Rejecting re-init on previously-failed class java.lang.Class<uO>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/TracingController;
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
But this logcat is the same for websites which do load...
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
yesterday
|
show 3 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224239%2fxamarin-forms-webview-loading-mixed-content-in-android%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password