Welcome Guest Search | Active Topics | Sign In | Register

webView.LoadHtml() is not loading image Options
jkelly
Posted: Friday, December 1, 2017 8:25:39 AM
Rank: Advanced Member
Groups: Member

Joined: 2/26/2015
Posts: 53
I'm having an issue using LoadHtml, where text shows fine but showing an image just gives me a blank rectangle.

Below of my code snippet. The text "test" shows but my valid image path doesn't show the image.

When I viewsource and copy and paste the html generated and put into a file and view in a browser, it works fine.

Code: C#
webView1.LoadHtml("<HTML>" +
                                    "<BODY>test" +
                                    "<img src=\"file://C:\\file_path\\Image.png\" height=\"100%\" width=\"100%\">" +
                                    "</BODY>" +
                                    "</HTML>");


eo_support
Posted: Saturday, December 2, 2017 9:55:38 PM
Rank: Administration
Groups: Administration

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

This has to do with Chromium browser engine's web security policy. The basic rules are:

1. Only a file scheme page can load a file scheme resource. So for example, if an Internet based page try to have an image with local file path. the request to that image will be denied;

2. Rule 1 does not apply if EnableWebSecurity is turned off:

https://www.essentialobjects.com/doc/eo.webengine.browseroptions.enablewebsecurity.aspx

To workaround rule 1, you would need to make sure the WebView's current scheme is a file scheme. So if you call WebView.LoadUrl to load a local file Url first, you will be able to call LoadHtml to load HTML that references local resources. Alternatively, you can apply rule 2 by setting EnableWebSecurity to false. See here for more details on how to use this option:

https://www.essentialobjects.com/doc/webbrowser/advanced/browser_options.aspx

Hope this helps. Please let us know if you still have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.