Requirements: If the customer's machine cannot access the external web website (for example, a music player software based on WebView2 can be used to play local songs normally without the network), WebView2 will not be able to access the external network resources and cannot be displayed, so the software will not work properlyEmbed HTML, CSS, JS resources into the installation package to allow WinFrom to load the customer's local file resourcesThis? Another advantage of packaging HTML, CSS, and JS code into the installation package is that it is not affected by the user's internet speed, because WebView2 reads files directly from the customer's premises.
Review:
Angular compilation package
The frontend is developed using the angular framework and packaged with the following command:
The packaged generated HTML, CSS, JS files as shown in the figure below:
WinFrom Web Hosting and Folder Mapping
Requires the use of WebView2 to load local web resources normallySetVirtualHostNameToFolderMappingSet the mapping relationship between the domain name and the folder, and then access the set domain name through WebView2, refer to:The hyperlink login is visible.
Hostname rules: RFC 6761 retains several special-purpose domain names (e.g., .example, . test and .invalid). Note that using .local as a top-level domain is feasible but may cause delays during navigation. If you can, you should avoid using .local.
The C# code looks like this:
Where the SetVirtualHostNameToFolderMapping second folder parameter should make the installation package free up the address of the web resource to the local disk folder, I'm just testing here, so I wrote dead.
Run the WinFrom program and you can successfully load and render the local web resource as shown in the following figure:
(End)
|