C# 清除cookies的代码
作者:堕落天才 时间:2021-08-14 20:10:10
不同的浏览器会把cookie文件保存在不同的地方
以下是C# WebBrowser控件cookies的存放路径
C:\Users\{你的帐号名}\AppData\Local\Microsoft\Windows\INetCookies
cookies文件格式请查看相关资料
下面是清除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("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)
{
}
}
}
}
}
关于C# 清除cookies的代码就给大家写这么多,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
来源:http://www.cnblogs.com/iamlucky/archive/2016/10/29/6010858.html
标签:c#,清除,cookies
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中方法的使用、重载与递归的详细介绍
2022-03-02 02:50:05
![](https://img.aspxhome.com/file/2023/8/60928_0s.png)
springboot使用Logback把日志输出到控制台或输出到文件
2022-05-30 17:34:30
![](https://img.aspxhome.com/file/2023/3/63763_0s.png)
Java由浅入深刨析继承
2023-11-23 08:04:24
![](https://img.aspxhome.com/file/2023/4/59564_0s.jpg)
Java垃圾回收器的方法和原理总结
2022-06-27 07:11:46
![](https://img.aspxhome.com/file/2023/9/91069_0s.jpg)
Spring Boot Debug调试过程图解
2023-12-13 10:27:33
![](https://img.aspxhome.com/file/2023/7/62497_0s.png)
java8 stream 如何打印数据元素
2022-08-20 18:40:02
linux(center OS7)安装JDK、tomcat、mysql 搭建java web项目运行环境
2022-07-04 07:02:37
Mybatis + js 实现下拉列表二级联动效果
2022-09-14 03:43:06
![](https://img.aspxhome.com/file/2023/9/69699_0s.png)
C#纯技术之Class写入Json
2023-01-15 17:13:49
![](https://img.aspxhome.com/file/2023/0/88330_0s.png)
基于C#对用户密码使用MD5加密与解密
2022-11-24 23:05:23
Spring2.5.6开发环境搭建图文教程
2023-07-28 18:01:02
![](https://img.aspxhome.com/file/2023/4/74764_0s.jpg)
C#微信公众号开发之自定义菜单
2023-01-23 02:07:08
![](https://img.aspxhome.com/file/2023/9/68079_0s.png)
Java简单实现约瑟夫环算法示例
2023-04-04 09:59:41
![](https://img.aspxhome.com/file/2023/2/81342_0s.png)
C#导出文本内容到word文档的方法
2021-10-15 19:00:37
SpringBoot实现项目健康检查与监控
2023-10-28 19:14:25
Java抽象类和接口的区别详情
2023-05-23 20:09:59
一步步教你如何使用Java实现WebSocket
2023-06-07 04:18:20
![](https://img.aspxhome.com/file/2023/1/77971_0s.png)
SpringBoot集成EasyExcel的应用场景分析
2023-01-09 07:47:45
![](https://img.aspxhome.com/file/2023/6/78876_0s.png)
详解C#正则表达式Regex常用匹配
2022-07-08 08:04:45
SpringBoot整合ActiveMQ的详细步骤
2023-08-25 07:03:44