Skip to content

SetVirtualHostNameToFolderMapping - cWebView2Browser

Creates a virtual mapping between the provided host name and a local folder on disk

Type: Procedure

Parameters

Parameter Type Description
sHostName String Hostname to set up mapping for
sFolderPath String Local path to map to
eOptAccessKind OLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND Access for the virtual host nameOLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY orOLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW orOLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY_CORS

Syntax

Procedure SetVirtualHostNameToFolderMapping String sHostName String sFolderPath OLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND eOptAccessKind

Call Example

Send SetVirtualHostNameToFolderMapping sHostName sFolderPath eOptAccessKind

Description

Creates a virtual mapping between the provided host name and a local folder on disk. Files inside this folder can now accessed through the virtual host name as if they where on a web server. Using this technique helps getting around several security issues that browsers (including WebView2) impose on the file:// protocol.

The virtual hostname will also be used for cookies and local storage.

Sample

The example below shows how to map localdemo.asset to the AppHtml of the workspace:

Object oWebView2Browser is a cWebView2Browser
    Set Size to 87 250
    Set Location to 0 0
    Set peAnchors to anAll

    Procedure OnCreate
        String sPath

        Forward Send OnCreate

        Get psAppHtmlPath of (phoWorkspace(ghoApplication)) to sPath
        Send SetVirtualHostNameToFolderMapping "localdemo.asset" sPath OLECOREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW
        Set psLocationURL to "https://localdemo.asset/DemoWebView2.html"
    End_Procedure
End_Object