question

Kain-1742 avatar image
0 Votes"
Kain-1742 asked DanielZhang-MSFT answered

How to add a cookie list to WebView2 ?

How do I add multiple lines of cookies to webview2?

webView.CoreWebView2.CookieManager.CreateCookie () <- requires the format (string, string, string, string) and nothing else

webView.CoreWebView2.CookieManager.CreateCookieWithSystemNetCookie (Cookie cookie) <- allows you to add only 1 cookie

webView.CoreWebView2.CookieManager.AddOrUpdateCookie (CoreWebView2Cookie cookie) <- Not given result


I have txt file with 14 cookies NetScape (1 cookie = 1 string). I read file and write in

List<string> cookie List<string>();

None of the above methods allow me to download all 14 cookies and follow the link

dotnet-csharpwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi Kain-1742,
The link explains that WebView2 is still in active development, and does not yet have a cookies API.
It is recommended to handle the WebResourceRequested event and then setting a cookie by amending the request.Header from inside the WebResourceRequested event handler.
There are some code examples has been provided in the threads below you can refer to.
Set cookies for WebView2, in WebResourceRequested event
How to set cookies to WebView2 control in c#?
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.