欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 清除cookies的代碼

 更新時間:2016年10月30日 14:30:01   作者:墮落天才  
不同的瀏覽器會把cookie文件保存在不同的地方.這篇文章主要介紹了C# 清除cookies的代碼,需要的朋友可以參考下

不同的瀏覽器會把cookie文件保存在不同的地方

  以下是C# WebBrowser控件cookies的存放路徑

  C:\Users\{你的帳號名}\AppData\Local\Microsoft\Windows\INetCookies

  cookies文件格式請查看相關(guān)資料

下面是清除cookies的代碼:

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("#/");
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)
{
}
} 
}
}
}

關(guān)于C# 清除cookies的代碼就給大家寫這么多,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

相關(guān)文章

最新評論