Closed MichaelKetting closed 3 years ago
Hey @shyjusachin - This function will only set the cookie as a header when sending a request to the server. It is not saving the cookie locally. You can use the cookie APIs if you want to do that: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.cookiemanager?view=webview2-dotnet-1.0.1054.31#Microsoft_Web_WebView2_Core_CoreWebView2_CookieManager
Thank you @champnic for the quick reply. As per your response what I understood is based on my above code, it will send whatever the Cookies required for the domain. Here I am not used CookieManager Api so that it will not save into local storage.
Still my webview functionality is not working as expected, even here I am sending cookies with the header, url is redirected to login page due to lack of cookies availability. Could you please let me know what will the cause here, or how should I ensure cookies are available once the page is loading.
Please let me know any more information required my side. Expecting your feedback on it. Thank you
This sounds like it might be a mismatch between what is being sent as a cookie, and what the server is expecting. You can verify what cookies are being sent by looking in the DevTools Network tab, or by looking at a NetLog: https://textslashplain.com/2020/01/17/capture-network-logs-from-edge-and-chrome/ https://textslashplain.com/2020/04/08/analyzing-network-traffic-logs-netlog-json/
Is there any way to get (not set) a cookie from the WebView2 instance?
@ShaunLoganOracle @thepwrtank18 Yes you can use any of it based on your requirement
eg : Await WebView21.CoreWebView2.CookieManager.GetCookiesAsync(uri)
Are you looking for this API? https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2cookiemanager?view=webview2-dotnet-1.0.1150.38
Thanks; i'll will have a look into this. Kind Regards :)
I looked at the API docs (https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/iwebview2webview) but didn't see find a matching API, so here's the feature request:
It would be great to be able to get and set the cookies used by the WebView. Internet Explorer allows getting the cookies by calling InternetGetCookieEx() from wininet.dll.
With this feature you build an application that uses both the browser control and a side channel when interacting with a website.
Edit: Possibly, the WebResourceRequested event might allow access via the raw headers from the GetResponse method (https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/iwebview2webresourcerequestedeventargs#interface_i_web_view2_web_resource_requested_event_args) but that's quite the effort.
AB#27223320