不同的浏覽器會把cookie文件保存在不同的地方
以下是C# WebBrowser控件cookies的存放路徑
C:\Users\{你的帳號名}\AppData\Local\Microsoft\Windows\INetCookies

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace DelCookies
{
class Program
{
static void Main(string[] args)
{
DelCookies("360.cn/");
Console.WriteLine("cookies已刪除.");
Console.Read();
}
static void DelCookies(string domain) //domain是cookies所屬域,此方法是通過所屬域過濾清除cookies
{
//獲取目錄中文件路徑
string[] cookies = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
foreach (string file in cookies)
{
try
{
StreamReader sr = new StreamReader(file);
string txt = sr.ReadToEnd();
sr.Close();
if (txt.IndexOf(domain) != -1) //判斷是否刪除的cookies文件
{
File.Delete(file);
}
}
catch (Exception ex)
{
}
}
}
}
}
原文地址:http://www.cnblogs.com/iamlucky/p/6010858.html