Yes that is what that method is for. You define a host name (e.g. localassets.example
and then the folder to map it to. When the control sees the URL (e.g. https://localassets.example/index.htm
) then it loads the corresponding file from the folder you gave instead of making a call via the INet. In theory you can do this for any file since all it does is change where the file is being delivered from.
The docs have the best example of how to do this. But here's a quick example. Assume the hostedfiles
folder contains index.htm
, index.js
and image.png
files. Configure the host mapping that you need.
webView.CoreWebView2.SetVirtualHostNameToFolderMapping("localassets.example", "hostedfiles", CoreWebView2HostResourceAccessKind.Allow);
Finally in the index.htm file.
<!DOCTYPE html>
<html>
<head>
<Title>Local Site</Title>
</head>
<body>
<img src="https://localassets.example/image.png" />
<script src="https://localassets.example/index.js"></script>
</body>
</html>