Hello,
 
I recently search for a method to delete all cookies from the build in .NET WinForms WebBrowser control.
 
I didn't found any working solution for it, nor working example.
It being told to use InternetSetOption, but nothing found about it.
 
So, i will write here my solution for clearing and deleting all cookies.
My solution using InternetSetOption with the option flag: INTERNET_OPTION_SUPPRESS_BEHAVIOR, which described as:
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.
 
This option flag should be used together with INTERNET_SUPPRESS_COOKIE_PERSIST options, which means:

Suppresses the persistence of cookies, even if the server has specified them as persistent.

So the example code for it will be:

static void Main()
{
SuppressWininetBehavior(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
} [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); 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)3/* INTERNET_SUPPRESS_COOKIE_PERSIST*/;
int* optionPtr = &option; bool success = InternetSetOption(0, 81/*INTERNET_OPTION_SUPPRESS_BEHAVIOR*/, new IntPtr(optionPtr), sizeof(int));
if (!success)
{
MessageBox.Show("Something went wrong !>?");
}
}
Please make sure your project is allows unsafe code. (under Properties => Build Tab)

This code is deleting the COOKIES per PROCESS on startup ONLY. 
[tested on WIN-7 and working great]

 
 
http://mdb-blog.blogspot.com/2013/02/c-winforms-webbrowser-clear-all-cookies.html?showComment=1400640795248#c48436006945190670

c# Winforms WebBrowser - Clear all cookies的更多相关文章

  1. [Cookie] Clear Cookie

    import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport def myCookies = testRunner.testCa ...

  2. C# 清除cookies

    不同的浏览器会把cookie文件保存在不同的地方 以下是C# WebBrowser控件cookies的存放路径 C:\Users\{你的帐号名}\AppData\Local\Microsoft\Win ...

  3. Chrome 开发工具之Network

    经常会听到比如"为什么我的js代码没执行啊?","我明明发送了请求,为什么反应?","我这个网站怎么加载的这么慢?"这类的问题,那么问题既然 ...

  4. sqlHelper做增删改查,SQL注入处理,存储值,cookie,session

    一.存储值 eg:登录一个页面,在进入这个页面之前你怎么知道它登没登录呢?[在登录成功之后我们把状态保存起来] 存储值得方式有两种,一种是cookie,一种是session 1.1区别: 代码: if ...

  5. Fiddler2 主菜单

    Fiddler2 主菜单 六个主菜单分别是: 文件(File) Capture Traffic ——启用捕获功能,快捷键 F12 此功能的开启/关闭状态,程序安装后默认是开启的.可以在 Fiddler ...

  6. Jquery Ajax处理,服务端三种页面aspx,ashx,asmx的比较

    常规的Jquery Ajax 验证登录,主要有3种服务端页面相应 ,也就是 aspx,ashx,asmx即webserivice . 下面分别用3种方式来(aspx,ashx,asmx)做服务端来处理 ...

  7. ASIHTTPREQUEST 文档

    http://blog.csdn.net/ysysbaobei/article/details/17026577 Please note that I am no longer working on ...

  8. 详解Google Chrome浏览器(操作篇)(下)

    开篇概述 由于最近忙于公司产品的架构与研发,已经三个多月没有写博客了,收到有些朋友的来信,问为什么不及时更新博客内容呢,他们说他们正期待着某些内容.对此,非常抱歉,那么我在此也给各位朋友一些承诺,从即 ...

  9. Chrome DevTools 调研笔记

    1  说明 此篇文章针对Chrome DevTools常用功能进行调研分析.描述了每个功能点能实现的功能.应用场景和详细操作. 2  Elements 2.1  功能 检查和实时更新页面的HTML与C ...

随机推荐

  1. Rest-Assured

    Rest-Assured完整的测试例子 http://blog.csdn.net/win7system/article/details/52468078 使用 Rest-assured 测试 Rest ...

  2. 花生壳+Tomcat

    花生壳(内网穿透)新手上路 http://service.oray.com/question/1664.html 好不容易找到一篇关于“花生壳+Tomcat”的好文章,转一下,上次自己弄的时候把自己的 ...

  3. linux笔记:linux帮助命令,man,help,whatis,apropos

    命令名称:man功能:获得帮助信息命令所在路径:/usr/bin/man用法:man 命令或配置文件其他:会调用less来查看该命令或配置文件的帮助信息. 命令名称:whatis功能:获得命令的简短介 ...

  4. 日期操作类--Date类

    Date-API ava.util包提供了Date类来封装当前的日期和时间.Date类提供两个构造函数来实例化Date对象.第一个构造函数使用当前日期和时间来初始化对象. Date( ) 第二个构造函 ...

  5. Question store (Repeated review)

    题目36 - ACM在线评测系统http://acm.nyist.net/JudgeOnline/problem.php?pid=36 用户名密码INVATION  讲道理太卡 第一:要注意不同的函数 ...

  6. 【Linux】rpm -qa 和 rpm -q

    查询一个包是否被安装 # rpm -q < rpm package name>列出所有被安装的rpm package # rpm -qae.g. rpm -qa|grep "pc ...

  7. HTML5自学笔记[ 20 ]canvas绘图实例之绘制倒影

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. c# BackGroundWorker 多线程操作的小例子

    在我们的程序中,经常会有一些耗时较长的运算,为了保证用户体验,不引起界面不响应,我们一般会采用多线程操作,让耗时操作在后台完成,完成后再进行处理或给出提示,在运行中,也会时时去刷新界面上的进度条等显示 ...

  9. hdu---1024Max Sum Plus Plus(动态规划)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. Extjs中处理mouseover的闪烁问题

    在使用mouseover和mouseout实现鼠标滑动效果并且target的dom较复杂时,可能会产生闪烁现象,产生这个问题的一个原因是mouseover事件本身的冒泡特性和target dom的子元 ...