locked
[UWP] Clear single webview session/cookies with multiple webviews RRS feed

  • Question

  • In my app Playlist Converter I let users connect to Spotify, Napster, Deezer and Youtube by their web services. I want to give the users an option to switch accounts at those web services. Now I use await WebView.ClearTemporaryWebDataAsync(); but that resets all the sessions and what I want is to clear just the session of one of the web services. And even with ClearTemporaryWebDataAsync the web service of Deezer still signs in with the previous account, until I close the app and reopen it. How can I implement such a function that I only clear the browser session of one specific web service?

    Edit:

    Solved:

    HttpBaseProtocolFilter baseFilter = new HttpBaseProtocolFilter();
    foreach (var cookie in baseFilter.CookieManager.GetCookies(AuthorizeUri))
    {
      baseFilter.CookieManager.DeleteCookie(cookie);
    }

    And then not using await WebView.ClearTemporaryWebDataAsync();

    Regards,

    Dennis Bakker


    Developer of the UWP app Playlist Converter

    Friday, March 31, 2017 2:34 PM

Answers

  • Hello DennisBakker71,

    Great. I would help you make your solution as answer. If you come back, you could mark it as answer. It would be helpful to other developer who’re looking for the result of the same question. Thanks.

    The solution is using the GetCookies(Uri) method of HttpCookieManager class to get the cookie of specific Uri, and then using DeleteCookie(HttpCookie) method to delete it.

    HttpBaseProtocolFilter baseFilter = new HttpBaseProtocolFilter();
    foreach (var cookie in baseFilter.CookieManager.GetCookies(AuthorizeUri))
    {
      baseFilter.CookieManager.DeleteCookie(cookie);
    }

    Best Regards,

    Xavier Eoro


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 3, 2017 5:39 AM