无法在Windows Phone 8中清除WebBrowser控件的缓存

时间:2014-12-01 11:20:18

标签: caching windows-phone-8 cookies webbrowser-control

我在windows phone应用程序中使用了WebBrowser控件。使用webbrowser控件我正在登录我的应用程序。在注销时,我只需将用户重定向到登录页面,然后尝试清除web浏览器控件的缓存和cookie。

mybrowser.ClearCookiesAsync();
mybrowser.ClearInternetCacheAsync();

而不是显示登录屏幕,它获取以前的凭据并登录到应用程序中。任何人都可以帮我清除webbrowser conteol的cookie和缓存。 完整代码:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            App.AccessToken = "";
            myBrowser.Navigate(new Uri(login URL));

        }
        void Navigating(object sender, NavigatingEventArgs e)
        {
            if (Login complete)
            {
                clearCahe();
            }
        }
public async void clearCahe()
        {
            await myBrowser.ClearCookiesAsync();
            await mybrowser.ClearInternetCacheAsync();
        }

1 个答案:

答案 0 :(得分:0)

async functions难以使用。如果你把断点放在

await myBrowser.ClearCookiesAsync();  // put a break point here then step-in (F11 on the keyboard)

你会看到它实际上并没有等待,并会继续它的快乐方式。

要解决这个问题,你必须做这样的事情

using System.Threading.Task;

public async Task<bool> clearCahe()
{
    await myBrowser.ClearCookiesAsync();
    await mybrowser.ClearInternetCacheAsync();
    return true;
}    

和一个同步的调用函数

喜欢这样

private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    await clearCache();
    // then navigate the page
}
相关问题