【总结】清除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 ...
随机推荐
- 浅谈oracle10G spfile与pfile(转)
转自:http://blog.csdn.net/onebigday/article/details/6108348,http://www.linuxidc.com/Linux/2012-11/7371 ...
- Happy New Year
今年的元旦能明显感觉到节日的狂欢.一方面,论文的事情,压抑了好久,另一方面,把自己融入节日之中.所以才有了节日的深度参与. 早上还是按时的起床,看了朋友圈,内心却能专注于平静.因为见到了优秀的人,才发 ...
- 二模15day1解题报告
T1.合并序列(minval) 给出长为 n的AB两个序列求两两相加中最小的n个. 据说有证明(在蓝书上,优先队列部分)先把A[1~n]+b[1]入队,然后每取一个a[x]+b[y]就把a[x]+b[ ...
- js prepend() 和append()区别
prepend() 方法在被选元素的开头(仍位于内部)插入指定内容.prepend() 语法:$(selector).prepend(content) 或 $(selector).prepend(fu ...
- Product Backlog
会议时间:周四中午13:20-14:20 会议地点:寝室 讨论了如何根据用户故事来写排球的程序.如何实现单机模式的基本加分判断胜负的功能.并选出项目测试人员.然后两个人一个小组进行程序基本功能的开发. ...
- Hsqldb安装与使用
HSQLDB是一个轻量级的纯Java开发的开放源代码的关系数据库系统,其体积小,占用空间小,使用简单,支持内存运行方式等特点.可以在http://sourceforge.net/projects/hs ...
- Maximo-删除应用程序
执行如下SQL: delete from maxapps where app='<APPLICATION NAME>';delete from maxpresentation where ...
- 使用HttpURLConnection下载图片
import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.Ht ...
- FusionCharts中仪表盘相关属性
上上周用FusionCharts做了几个报表,里面有个仪表盘,当时查属性查疯了,现在把相关的一些属性记下来,方便以后查找. -------------------------仪表盘重要属性解析---- ...
- centos6配置网卡
#设置开机启动和静态地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 HWADDR=D8::E6::3F:CF TYPE=Ethe ...
