This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5331|Reply: 1

[Source] [WebView2] (5) Loading local HTML resources of the virtual host

[Copy link]
Posted on 10/10/2022 4:41:42 PM | | | |
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:

[WebView2] (1) Initial introduction to Microsoft Edge WebView2 technology
https://www.itsvse.com/thread-10361-1-1.html

[WebView2] (2) WinForm introduces WebView2 to display web content
https://www.itsvse.com/thread-10362-1-1.html

WebView2 (3) Bidirectional communication between the Web and WinForm applications
https://www.itsvse.com/thread-10364-1-1.html

[WebView2] (4) Web and WinForm call function methods to each other
https://www.itsvse.com/thread-10365-1-1.html

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)




Previous:【Turn】CURL command uses proxies and proxies are introduced
Next:Xshell 7 View the session password saved on the local computer
Posted on 3/31/2023 9:21:20 AM |
Thank you for sharing, I am learning
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com