Table of Contents

Class CoreWebView2CookieManager

Namespace
Microsoft.Web.WebView2.Core
Assembly
Microsoft.Web.WebView2.Core.dll

Creates, adds or updates, gets, or or view the cookies.

public class CoreWebView2CookieManager
Inheritance
CoreWebView2CookieManager
Inherited Members

Remarks

The changes would apply to the context of the user profile. That is, other WebViews under the same user profile could be affected.

Methods

AddOrUpdateCookie(CoreWebView2Cookie)

Adds or updates a cookie with the given cookie data; may overwrite cookies with matching name, domain, and path if they exist.

public void AddOrUpdateCookie(CoreWebView2Cookie cookie)

Parameters

cookie CoreWebView2Cookie

The CoreWebView2Cookie to be added or updated.

Examples

Remarks

This method will fail if the domain of the given cookie is not specified.

CopyCookie(CoreWebView2Cookie)

Creates a cookie whose params matches those of the specified cookie.

public CoreWebView2Cookie CopyCookie(CoreWebView2Cookie cookieParam)

Parameters

cookieParam CoreWebView2Cookie

Returns

CoreWebView2Cookie

CreateCookie(string, string, string, string)

Creates a cookie object with a specified name, value, domain, and path.

public CoreWebView2Cookie CreateCookie(string name, string value, string Domain, string Path)

Parameters

name string

The name for the CoreWebView2Cookie to be created. It cannot start with whitespace(s).

value string
Domain string
Path string

Returns

CoreWebView2Cookie

Remarks

One can set other optional properties after cookie creation. This only creates a cookie object and it is not added to the cookie manager until you call AddOrUpdateCookie(CoreWebView2Cookie). name that starts with whitespace(s) is not allowed.

Creates a CoreWebView2Cookie object whose params matches those of the given System.Net.Cookie.

public CoreWebView2Cookie CreateCookieWithSystemNetCookie(Cookie systemNetCookie)

Parameters

systemNetCookie Cookie

A System.Net.Cookie whose params to be used to create a CoreWebView2Cookie.

Returns

CoreWebView2Cookie

An object whose Name, Value, Path, Domain, IsHttpOnly, IsSecure, and Expires, matches those Name, Value, Path, Domain, HttpOnly, Secure, and Expires of the given Cookie object.

The default value for the SameSite property of the returned CoreWebView2Cookie object is Lax.

See Also

DeleteAllCookies()

Deletes all cookies under the same profile.

public void DeleteAllCookies()

Remarks

This could affect other WebViews under the same user profile.

DeleteCookie(CoreWebView2Cookie)

Deletes a cookie whose name and domain/path pair match those of the specified cookie.

public void DeleteCookie(CoreWebView2Cookie cookie)

Parameters

cookie CoreWebView2Cookie

DeleteCookies(string, string)

Deletes cookies with matching name and uri.

public void DeleteCookies(string name, string uri)

Parameters

name string

The name for the cookies to be deleted is required.

uri string

If uri is specified, deletes all cookies with the given name where domain and path match provided URI.

DeleteCookiesWithDomainAndPath(string, string, string)

Deletes cookies with matching name and domain/path pair.

public void DeleteCookiesWithDomainAndPath(string name, string Domain, string Path)

Parameters

name string

The name for the cookies to be deleted is required.

Domain string

If domain is specified, deletes only cookies with the exact domain.

Path string

If path is specified, deletes only cookies with the exact path.

GetCookiesAsync(string)

Gets a list of cookies matching the specific URI.

public Task<List<CoreWebView2Cookie>> GetCookiesAsync(string uri)

Parameters

uri string

If uri is empty string or null, all cookies under the same profile are returned.

Returns

Task<List<CoreWebView2Cookie>>

Examples

Remarks

You can modify the cookie objects by calling AddOrUpdateCookie(CoreWebView2Cookie), and the changes will be applied to the webview.