I'm setting a cookie using CoreWebView2.CookieManager.AddOrUpdateCookie
, example:
WebView2.Core.CoreWebView2Cookie cookie = webView21.CoreWebView2.CookieManager.CreateCookie("MyCookie", "123", "abc.com", "/");
cookie.IsHttpOnly = false;
cookie.IsSecure = true;
webView21.CoreWebView2.CookieManager.AddOrUpdateCookie(cookie);
Now when I try and check if the cookie has been set using:
List<Microsoft.Web.WebView2.Core.CoreWebView2Cookie> cookieList = await webView21.CoreWebView2.CookieManager.GetCookiesAsync("abc.com");
I get no cookies returned, however if I change "abc.com"
to ""
in the .GetCookiesAsync("")
I can see the cookie I created, so why am I not seeing the cookies even though I'm passing in the correct domain/filter. When passing in the blank domain filter, I see my cookie with the correct domain on it.
What am I doing wrong here?
To get the cookie you must specify the full Url
, not just the domain name.
In your case, add https://
in front of the url.
IMHO this is a bug, since cookies don't work with urls, they work with domains.