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.
android xamarin webview xamarin.forms mixed-content
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.
android xamarin webview xamarin.forms mixed-content
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.
android xamarin webview xamarin.forms mixed-content
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.
android xamarin webview xamarin.forms mixed-content
android xamarin webview xamarin.forms mixed-content
asked Nov 9 at 10:47
mrd
1,84983972
1,84983972
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 theWebView
will allow an HTTPS origin to load content from an HTTP origin.
NeverAllow
– indicates that theWebView
will not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode
– indicates that theWebView
will 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
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
|
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 theWebView
will allow an HTTPS origin to load content from an HTTP origin.
NeverAllow
– indicates that theWebView
will not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode
– indicates that theWebView
will 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
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
|
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 theWebView
will allow an HTTPS origin to load content from an HTTP origin.
NeverAllow
– indicates that theWebView
will not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode
– indicates that theWebView
will 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
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
|
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 theWebView
will allow an HTTPS origin to load content from an HTTP origin.
NeverAllow
– indicates that theWebView
will not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode
– indicates that theWebView
will 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 theWebView
will allow an HTTPS origin to load content from an HTTP origin.
NeverAllow
– indicates that theWebView
will not allow an HTTPS origin to load content from an HTTP origin.
CompatibilityMode
– indicates that theWebView
will 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 Nov 9 at 11:01
answered Nov 9 at 10:54
Gerald Versluis
16.1k43256
16.1k43256
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
|
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
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
Nov 9 at 11:43
Tanks for the clear explanation. However, SettingMixedContentMode in code or in XAML does not resolve the issue. What else could be the problem?
– mrd
Nov 9 at 11:43
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
You should probably closely inspect the application output while running. It is nearly impossible to say with this little information, sorry.
– Gerald Versluis
Nov 9 at 11:45
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
Nov 9 at 12:35
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
Nov 9 at 12:35
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
But this logcat is the same for websites which do load...
– mrd
Nov 9 at 12:38
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
[X509Util] Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
– mrd
Nov 9 at 13:02
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown