Is it possible to access embedded resources of the assembly itself instead of local folders?
Is it possible to access embedded resources of the assembly itself instead of local folders? I just want to package it into a single-file application
@VAllens apologies for the late response.
If you mean WebView2 core assemblies? At the beginning they were. I am not sure now that is it GA. But you can try. If you mean something else. Please explain.
Thanks.
@mattkol
I searched google for the keyword SetVirtualHostNameToFolderMapping and found this place.
I have some static resource files (html, js, css, etc...).
If I decide not to embed them in an assembly resource,
then I can use the SetVirtualHostNameToFolderMapping method to map them to a local folder so they are ready to use out of the box.
If I decide to embed them in an assembly resource,
then I need to do extra work to handle some events, parse the request, and fetch the target resource from the assembly resource and finally respond.
I decide to embed them in an assembly resource, i solved it.
I don't want these static resource files to be exposed to users or visible in any directory on the computer. And to prevent users from tampering with these static resource files, I embed them in the assembly resources.
I decide to embed them in an assembly resource, i solved it.
Cool! If this something you think will be useful for others, you can share a bare skeletal version. Thanks.
Of course. Let's embrace open source !!!
I will take the time to organize the code and then share it. Here are a few methods and events to keep an eye on:
CoreWebView2InitializationCompletedCoreWebView2.WebResourceRequestedCoreWebView2.AddWebResourceRequestedFilter($"file://your_custom_alias/*", CoreWebView2WebResourceContext.All)CoreWebView2.Environment.CreateWebResourceResponse(...)Assembly.GetExecutingAssembly().GetManifestResourceStream(...)
We register the CoreWebView2InitializationCompleted event.
Then in the CoreWebView2InitializationCompleted callback method,
we register the internal events of CoreWebView2.WebResourceRequested and call CoreWebView2.AddWebResourceRequestedFilter method.
We process the file:// request in the CoreWebView2.WebResourceRequested callback method,
fetch the assembly resource file by relative URL, and respond stream.
Be careful. Be sure to use file:// instead of http://.
Issues: 2 seconds delay is seen with Page navigation using WebView2 & SetVirtualHostNameToFolderMapping