【总结】清除webbrowser cookie/session的6种方法
下面是我测试下来的6种清除webbrowser中cookie的6种方法:
//方法一:调用 wininet.dll清除cookie (推荐)
SuppressWininetBehavior(); //方法二:删除用户登录后的信息,这里相当于浏览器的注销功能,使用的是ie自带的功能 (推荐)
HtmlDocument document = wb.Document;
document.ExecCommand("ClearAuthenticationCache", false, null); //方法三:删除本机cookie 此方法会弹出ie清除cookie的弹出框
//Temporary Internet Files (Internet临时文件)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
//Cookies
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
//History (历史记录)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
//Form. Data (表单数据)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
//Passwords (密码)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
//Delete All (全部删除)
//ShellExecute(IntPtr.Zero, "open", "rundll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 2", "", ShowCommands.SW_HIDE);
ShellExecute(IntPtr.Zero, "open", "rundll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 255", "", ShowCommands.SW_HIDE); //方法四:使用webbrowser自带的清coookie的方法 (不推荐,清不掉session,实测无效)
wb.Document.Cookie.Remove(, (wb.Document.Cookie.Count() - )); //方法五:使用js清除cookie (不推荐,清不掉session)
wb.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString());}}}})())");
//var a,b,c,e,f;
//f=0;
//a=document.cookie.split('; ');
//b='.'+'baidu.com';
////b='.'+'www.baidu.com';
//for(e=0;e<a.length;e++){
// //b='.'+location.host;
// b=b.replace(/^(?:%5C.|[^%5C.]+)/,'');
// c=location.pathname;
// c=c.replace(/.$/,'');
// ck = a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString();
// console.log(ck);
// document.cookie=ck;
//} //方法六:使用InternetSetCookie给cookie赋null值 (不推荐)
//也可以给此Cookie赋空值:InternetSetCookie
//InternetSetCookie("http://.qq.com/", NULL, "uin=; PATH=/; DOMAIN=qq.com");
方法一:
[System.Runtime.InteropServices.DllImport("wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetOption(int hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
/// <summary>
/// 使用InternetSetOption操作wininet.dll清除webbrowser里的cookie
/// </summary>
private static unsafe void SuppressWininetBehavior()
{
/* SOURCE: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385328%28v=vs.85%29.aspx
* INTERNET_OPTION_SUPPRESS_BEHAVIOR (81):
* A general purpose option that is used to suppress behaviors on a process-wide basis.
* The lpBuffer parameter of the function must be a pointer to a DWORD containing the specific behavior to suppress.
* This option cannot be queried with InternetQueryOption.
*
* INTERNET_SUPPRESS_COOKIE_PERSIST (3):
* Suppresses the persistence of cookies, even if the server has specified them as persistent.
* Version: Requires Internet Explorer 8.0 or later.
*/
int option = (int)/* INTERNET_SUPPRESS_COOKIE_PERSIST*/;
int* optionPtr = &option;
bool success = InternetSetOption(, /*INTERNET_OPTION_SUPPRESS_BEHAVIOR*/, new IntPtr(optionPtr), sizeof(int));
if (!success)
{
MessageBox.Show("Something went wrong ! Clear Cookie Failed!");
}
}
方法二:
就只有这一句就好了:
//方法二:删除用户登录后的信息,这里相当于浏览器的注销功能,使用的是ie自带的功能 (推荐)
HtmlDocument document = wb.Document;
document.ExecCommand("ClearAuthenticationCache", false, null);
方法三:
//方法三:删除本机cookie 此方法会弹出ie清除cookie的弹出框
//Temporary Internet Files (Internet临时文件)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
//Cookies
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
//History (历史记录)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
//Form. Data (表单数据)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
//Passwords (密码)
//RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
//Delete All (全部删除)
//ShellExecute(IntPtr.Zero, "open", "rundll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 2", "", ShowCommands.SW_HIDE);
ShellExecute(IntPtr.Zero, "open", "rundll32.exe", " InetCpl.cpl,ClearMyTracksByProcess 255", "", ShowCommands.SW_HIDE);
ShellExecute方法:
public enum ShowCommands : int
{ SW_HIDE = , SW_SHOWNORMAL = , SW_NORMAL = , SW_SHOWMINIMIZED = , SW_SHOWMAXIMIZED = , SW_MAXIMIZE = , SW_SHOWNOACTIVATE = , SW_SHOW = , SW_MINIMIZE = , SW_SHOWMINNOACTIVE = , SW_SHOWNA = , SW_RESTORE = , SW_SHOWDEFAULT = , SW_FORCEMINIMIZE = , SW_MAX = } [DllImport("shell32.dll")]
static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, ShowCommands nShowCmd);
方法四:
//方法四:使用webbrowser自带的清coookie的方法 (不推荐,清不掉session,实测无效)
wb.Document.Cookie.Remove(, (wb.Document.Cookie.Count() - ));
方法五:
//方法五:使用js清除cookie (不推荐,清不掉session)
wb.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString());}}}})())");
//var a,b,c,e,f;
//f=0;
//a=document.cookie.split('; ');
//b='.'+'baidu.com';
////b='.'+'www.baidu.com';
//for(e=0;e<a.length;e++){
// //b='.'+location.host;
// b=b.replace(/^(?:%5C.|[^%5C.]+)/,'');
// c=location.pathname;
// c=c.replace(/.$/,'');
// ck = a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString();
// console.log(ck);
// document.cookie=ck;
//}
将 wb.Navigate("javascript:void((function(){。。。}里的内容换成下面注释掉的代码,写好你要清cookier 的domain然后就可以清了,但清不掉session,这个是从外国网站上看来的,实际无效!
方法六:
//方法六:使用InternetSetCookie给cookie赋null值 (不推荐)
//也可以给此Cookie赋空值:InternetSetCookie
//InternetSetCookie("http://.qq.com/", NULL, "uin=; PATH=/; DOMAIN=qq.com");
关于InternetSetCookie这个方法自己网上搜索一下.
【总结】清除webbrowser cookie/session的6种方法的更多相关文章
- Asp.Net保存session的三种方法
C#中保存Session的三种方法及Web.Config设置 1.保存session到sql server,需要指定Sql Server服务器,这种方法因为要读写数据库最慢 <sessionSt ...
- Asp.Net保存session的三种方法 (Dll文件更新导致session丢失的解决办法)
1. InProc模式(默认值):asp.net将session保存到当前进程中,这种方式最快,但是不能多台服务器共享session,且会话状态数据容易丢失. <sessionState mod ...
- linux-CentOS6.4安装Memcached+memcached扩展+安装memcache扩展+Memcache+mecached同步SESSION的几种方法
一.编译环境的准备 yum install gcc yum install gcc-c++ libstdc++-devel yum install zlib-devel 二.源代码包准备 wget ...
- css清除浮动大全,共8种方法
我看的网页的网址:http://hi.baidu.com/kongcheng2012/item/2b1250d4452e802538f6f705 为什么浮动这么难? 因为浮动会使当前标签产生向上浮的效 ...
- Spring MVC 中获取session的几种方法
Spring MVC 中使用session是一种常见的操作,但是大家上网搜索一下可以看到获取session的方式方法五花八门,最近,自己终结了一下,将获取session的方法记录下来,以便大家共同学习 ...
- Struts2中使用Session的两种方法
在Struts2里,如果需要在Action中使用到session,可以使用下面两种方式: 通过ActionContext 类中的方法getSession得到 Action实现org.apache.st ...
- Oracle 手工清除回滚段的几种方法
关于回滚段的问题,之前也小整理过一个,参考: Current online Redo 和 Undo 损坏的处理方法 http://blog.csdn.net/tianlesoftware/articl ...
- cookie 常用的几种方法
{ setCookie: function(sName, sValue, oExpires, sPath, sDomain, bSecure) { var sCookie = sName + &quo ...
- Asp.Net Session的三种方法及Web.Config设置
转载:http://user.gw-ec.com/login/safelog/redirectt?session=so%2f%2bSjyZURMOe54xgk%2bUhL2CgGqDjOKEbYwZS ...
随机推荐
- MySql绿色版下载,安装,配置详解
下载完成之后解压,楼主用的版本是:mysql-5.7.15-winx64 解压完在根目录下建立一个data文件夹和my-default.ini my-default.ini里面的内容如下:(红色内容根 ...
- 在CentOS或RHEL防火墙上开启端口
转载自:https://linux.cn/article-4243-1.html 如果希望在服务器上提供服务,诸如CentOS或RHEL的企业级Linux发行版包含内置的强大防火墙,它们默认的防火墙规 ...
- js面向对象的实现(example 一)
//通过函数原型链(prototype)的方式来构造对象 //通过闭包的方式来对元素类进行封装 //通过函数原型链的方式来构造对象的方法和类的继承 //通过以上步骤就可以用函数的形式来实现类的,封装, ...
- 从request获取远程IP地址
public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-F ...
- 深入理解CSS溢出overflow & overflow:hidden真的失效了吗[转载]
深入理解CSS溢出overflow http://www.cnblogs.com/xiaohuochai/p/5289653.html overflow:hidden真的失效了吗 http://www ...
- sqlserver如何关闭死锁进程.
1.首先我们需要判断是哪个用户锁住了哪张表. --查询被锁表 select request_session_id spid,OBJECT_NAME(resource_associated_entity ...
- FPS中受伤UI在VR游戏中的实现思路
FPS中受伤UI在VR游戏中的实现思路 希望实现的效果 这几天一直在尝试各种解决方案,现在算是不完美的解决啦,记录一下心路历程,思路有了算法都比较简单. V_1 玩家胶囊体指向的方向作为正方向,计算出 ...
- 跨域的get和post的区别
GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二.最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数.当你在面试中被 ...
- linux网络学习
ipv4报文处理流程 1.物理层网卡收到报文,产生中断进入中断处理程序:net_interrupt,判断中断是由接收到分组引发后,控制权转移到net_rx: 2.net_rx函数分配一个新的sk_bu ...
- tracert与pathping
trace route(windows命令为tracert,Linux命令为traceroute)命令可以列出本地计算机与目标计算机之间所有经过的计算机信息.可以输入目标计算机的名字(如www.bai ...
