在WPF中使用C#代码删除IE缓存和Cookies [英] Deleting IE Cache and Cookies using C# Code in WPF

查看:106
本文介绍了在WPF中使用C#代码删除IE缓存和Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF应用程序中使用了WebBrowser控件,并且希望从代码中清除IE cookie缓存.

I am using a WebBrowser control in my WPF application and I am looking to clear the IE cookie cache from code.

我尝试使用以下代码

string[] Cookies = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
foreach (string currentFile in Cookies)
{
  try
  {
    System.IO.File.Delete(currentFile);
  }

  catch (Exception ex)
  {
    MessageBox.Show(ex.Message);
  }
}

这将从指定的文件夹中删除文件,但是当我使用WebBrowser控件向后浏览时,Cookie会重新出现,就像它们从未被删除一样.

This deletes the files from the specified folder, but when I navigate back using the WebBrowser control, the cookies reappear as though they were never deleted.

这可能是正确的结果,因为我假设Environment.SpecialFolder.Cookies文件夹位于AppData中,这是用户最新动态的快照.

This might be the right result, as I am assuming that the Environment.SpecialFolder.Cookies folder is in AppData which is a current snapshot of what the user is up to.

如果我打开IE,并硬删除Cookie和缓存,则会在我的应用程序中获得预期的输出.

If I open up IE, and do a hard delete of cookies and cache I get the expected output in my app.

有没有办法在代码中执行此操作?

Is there a way to do this action in code?

推荐答案

Microsoft KB文章将帮助您更好地清除整个缓存.

The Microsoft KB Article will help you better and clear the entire Cache.

引用链接

但是,您也可以尝试以下解决方案.

However, You can try the following solution too.

string[] InterNetCache = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));

这篇关于在WPF中使用C#代码删除IE缓存和Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆