Web View2.Add Web Resource Requested Filter(String, CoreWebView2WebResourceContext) Method
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a URI and resource context filter for the WebResourceRequested event.
public void AddWebResourceRequestedFilter (string uri, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext ResourceContext);
member this.AddWebResourceRequestedFilter : string * Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext -> unit
Public Sub AddWebResourceRequestedFilter (uri As String, ResourceContext As CoreWebView2WebResourceContext)
A resource context filter to be added to the WebResourceRequested event.
Adds a URI and resource context filter for the WebResourceRequested event. A web resource request with a resource context that matches this filter's resource context and a URI that matches this filter's URI wildcard string will be raised via the WebResourceRequested event.
uri parameter value is a wildcard string matched against the URI of the web resource request. This is a glob style wildcard string in which a
* matches zero or more characters and a
? matches exactly one character. These wildcard characters can be escaped using a backslash just before the wildcard character in order to represent the literal
The matching occurs over the URI as a whole string and not limiting wildcard matches to particular parts of the URI. The wildcard filter is compared to the URI after the URI has been normalized, any URI fragment has been removed, and non-ASCII hostnames have been converted to punycode.
nullptr for the uri is equivalent to an empty string which matches no URIs.
For more information about resource context filters, navigate to CoreWebView2WebResourceContext.
|URI Filter String||Request URI||Match||Notes|
|https://contoso.com/a/b/c||Yes||A single * will match all URIs|
|https://contoso.com/a/b/c||Yes||Matches everything in contoso.com across all schemes|
|https://example.com/?https://contoso.com/||Yes||But also matches a URI with just the same text anywhere in the URI|
|https://contoso.com/example||No||The filter does not perform partial matches|
|https://contoso.com/example||Yes||The filter matches across URI parts|
|https://contoso.com/path/?example||Yes||The filter matches across URI parts|
|https://contoso.com/path/?query#example||No||The filter is matched against the URI with no fragment|
|https://example||No||The URI is normalized before filter matching so the actual URI used for comparison is https://example.com/|
|https://example||Yes||Just like above, but this time the filter ends with a / just like the normalized URI|
|https://xn--qei.example/||https://❤.example/||Yes||Non-ASCII hostnames are normalized to punycode before wildcard comparison|
|https://❤.example/||https://xn--qei.example/||No||Non-ASCII hostnames are normalized to punycode before wildcard comparison|