How to clear WebView cookies in MAUI for windows?

Karthik Nagamani 20 Reputation points

I am trying to logout our webview data.

Clearing cookies in Windows for MAUI doesn't seems to be working.

I am trying with this code:

Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new global::Windows.Web.Http.Filters.HttpBaseProtocolFilter();
                var cookieManager = myFilter.CookieManager;
HttpCookieCollection myCookieJar = cookieManager.GetCookies(new Uri("url"));
                foreach (HttpCookie cookie in myCookieJar)

I am not getting any cookies count.

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,207 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 29,206 Reputation points Microsoft Vendor


    MAUI that targets Windows platform uses WinUI3, you can try getting the native platform view (WebView2) with WebViewHandler on Windows, then clean cookie by CoreWebView2CookieManager.DeleteAllCookies Method. Please refer to the following code:


            <Button Text="ClearCookie" Clicked="Button_Clicked"></Button>  
            <WebView x:Name="MyWebview" Source="XXXX" HeightRequest="400" WidthRequest="400" ></WebView>  

    Clicking button to clean cookies.

    private void Button_Clicked(object sender, EventArgs e)
    #if WINDOWS
            var platformView = MyWebview.Handler.PlatformView as WebView2;

    Best Regards,

    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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 additional answers

Sort by: Most helpful