다음을 통해 공유


CoreWebView2CookieManager.GetCookiesAsync(String) Method

Definition

Gets a list of cookies matching the specific URI.

public System.Threading.Tasks.Task<System.Collections.Generic.List<Microsoft.Web.WebView2.Core.CoreWebView2Cookie>> GetCookiesAsync (string uri);
public System.Threading.Tasks.Task<Microsoft.Web.WebView2.Core.CoreWebView2CookieList> GetCookiesAsync (string uri);
member this.GetCookiesAsync : string -> System.Threading.Tasks.Task<System.Collections.Generic.List<Microsoft.Web.WebView2.Core.CoreWebView2Cookie>>
member this.GetCookiesAsync : string -> System.Threading.Tasks.Task<Microsoft.Web.WebView2.Core.CoreWebView2CookieList>
Public Function GetCookiesAsync (uri As String) As Task(Of List(Of CoreWebView2Cookie))
Public Function GetCookiesAsync (uri As String) As Task(Of CoreWebView2CookieList)

Parameters

uri
String

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

Returns

Examples

List<CoreWebView2Cookie> cookieList = await _iWebView2.CoreWebView2.CookieManager.GetCookiesAsync("https://www.bing.com");
StringBuilder cookieResult = new StringBuilder(cookieList.Count + " cookie(s) received from https://www.bing.com\n");
for (int i = 0; i < cookieList.Count; ++i)
{
    CoreWebView2Cookie cookie = _iWebView2.CoreWebView2.CookieManager.CreateCookieWithSystemNetCookie(cookieList[i].ToSystemNetCookie());
    cookieResult.Append($"\n{cookie.Name} {cookie.Value} {(cookie.IsSession ? "[session cookie]" : cookie.Expires.ToString("G"))}");
}
MessageBox.Show(this, cookieResult.ToString(), "GetCookiesAsync");

Remarks

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

Applies to