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 yesterday









      mrd

      1,83783871




      1,83783871






















          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
            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










          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






























          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
            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














          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
            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












          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 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
















          • 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

















           

          draft saved


          draft discarded















































           


          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














































































          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus