NavigateToStream. What URI (if any) is used for resolving relative links?

好久不见. 提交于 2020-01-11 10:11:48

问题


I have an WPF application which uses a <WebBrowser> object to display some content which is in turn wrapped in HTML -- I want to generate that HTML on the fly, but it will hold links to different kinds of static content which will be local files. In a normal web application, I would try to use relative URIs for this -- they will be looked up relative to the URI of the dynamic page.

The problem is if I use WebBrowser.NavigateToStream (or .NavigateToString). In this case what is the "root" URI used for resolving relative links? Can I control it? Is it fixed? Perhaps relative Uris are simply banned in such data streams.


回答1:


Try adding <base href="root_path"> into the <head> section of the generated page. It works with NavigateToString, at least:

this.webBrowser.NavigateToString(
    @"<head><base href='file://C:\Users\User\Documents\'></head><body><img src='image.jpg'></body>");


来源:https://stackoverflow.com/questions/21259565/navigatetostream-what-uri-if-any-is-used-for-resolving-relative-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!