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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 10:47









      mrd

      1,84983972




      1,84983972
























          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 the WebView will allow an HTTPS origin to load content from an HTTP origin.


          • NeverAllow – indicates that the WebView will not allow an HTTPS origin to load content from an HTTP origin.


          • CompatibilityMode – indicates that the WebView 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.







          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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 the WebView will allow an HTTPS origin to load content from an HTTP origin.


          • NeverAllow – indicates that the WebView will not allow an HTTPS origin to load content from an HTTP origin.


          • CompatibilityMode – indicates that the WebView 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.







          share|improve this answer























          • 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















          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 the WebView will allow an HTTPS origin to load content from an HTTP origin.


          • NeverAllow – indicates that the WebView will not allow an HTTPS origin to load content from an HTTP origin.


          • CompatibilityMode – indicates that the WebView 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.







          share|improve this answer























          • 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













          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 the WebView will allow an HTTPS origin to load content from an HTTP origin.


          • NeverAllow – indicates that the WebView will not allow an HTTPS origin to load content from an HTTP origin.


          • CompatibilityMode – indicates that the WebView 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.







          share|improve this answer














          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 the WebView will allow an HTTPS origin to load content from an HTTP origin.


          • NeverAllow – indicates that the WebView will not allow an HTTPS origin to load content from an HTTP origin.


          • CompatibilityMode – indicates that the WebView 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.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()