How to add a cookie list to WebView2 ?

Kain 1 Reputation point
2021-04-03T17:39:14.607+00:00

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

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,245 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-04-05T01:42:29.28+00:00

    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.

    0 comments No comments