Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set the cookies in Webview2 control in c#?

Here is how i am navigating the url into WebView2 control.

WebView.CoreWebView2.Navigate("URL Name");


I used the 'WebResourceRequested' event but there is no way to add headers into the request.

WebView.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
 private void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
        {
            strNavigationURL = e.Uri;
            e.RequestHeaders.????
        }


Since i need to pass the authorization token to this URL, Can someone help me to add the header value to the request?

What I have tried:

WebView.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
private void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
{
strNavigationURL = e.Uri;
e.RequestHeaders.????
}
Posted
Comments
Ravi Bhavnani 29-Oct-20 12:22pm    
Does this SO answer help?

https://stackoverflow.com/questions/21829442/set-cookies-to-webview-control

--Ravi
Remya Thomas 30-Oct-20 1:29am    
My requirement is to send the request with Cookies using WebView2 control through WinForms.

I tried the solution provided here, but it is not working with WebView control and with Webhttps://stackoverflow.com/questions/21829442/set-cookies-to-webview-control and with WebView2 as well. But both ways this is not working.

Webview control:-

webViewCompatible1.NavigateWithHttpRequestMessage(httpRequestMessage);
here NavigateWithHttpRequestMessage is not detected.

WebView2 control:-
is completely not working
Remya Thomas 30-Oct-20 1:31am    
FR:-I have asked the same in MSDN form as well
https://social.msdn.microsoft.com/Forums/en-US/1983408d-f9d9-44fd-a0c3-88b30d757644/how-to-set-cookies-to-webview2-control-in-c?forum=csharpgeneral

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900