【总结】清除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 ...
随机推荐
- 微信连wifi
微信连wifi 首先需要到微公众平台添加微信连wifi功能插件
- nvm
nvm install stable #安装最新稳定版 node,现在是 5.0.0 nvm install 4.2.2 #安装 4.2.2 版本 nvm install 0.12.7 #安装 0.1 ...
- Android IOS WebRTC 音视频开发总结(八十二)-- VP8对VP9,质量还是码率?
本文主要介绍VP9(我们翻译和整理的,译者:weizhenwei,校验:blacker),最早发表在[编风网] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:blacke ...
- TUniConnection连接
ChangeFileExt RealTime_Server.ini: [Config]FromConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzx ...
- 稳定灵活的 HTML 列式布局
主要特点: 所有列轻松实现相同高度 兼容性极高 ------------------------------------------------ 代码 ------------------------ ...
- PHP 7 vs HHVM 比较
PHP 是最流行的用于 web 开发的脚本语言之一.PHP 的最新版本,PHP 7 在性能上做了很大的优化.不过,PHP 还有一个竞争对手 HHVM (HipHop Virtual Machine) ...
- htnl5中设置文本单行显示,超出部分打省略号,鼠标移到文本时alt出全部文本内容
Html代码: 1.<span class="my-span" title="无数无数无数无数无数">机构</span> Css样式: ...
- Linux C 开发环境配置
换了新电脑,重装了Fedora10,所有开发环境都要重新配置啦,开个随笔记录下过程,说不定以后还要用~ 首先Fedora10装好之后是不带 VIM 的,果断安装之: 打开终端,首先 su 命令切换到r ...
- 学Android开发,入门语言java知识点
学Android开发,入门语言java知识点 Android是一种以Linux为基础的开源码操作系统,主要使用于便携设备,而linux是用c语言和少量汇编语言写成的,如果你想研究Android,就去学 ...
- Web前端开发:为何选择MVVM而非MVC
在Web中充斥着所谓的MVC框架,而在我看来,因为一些关键性的技术原因,MVC在Web前端开发中根本无法使用(对的,是无法,而不是不该) 在Web中充斥着所谓的MVC框架,而在我看来,因为一些关键性的 ...