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. Android 应用开发耗电量控制。。

    当程序启动手机越多的模块,那耗电就越快 当你的程序运行时只占用CPU的时候,这时候耗电量是最少的. 当然这时候如果cpu的运行速度很慢那是最好的.. 程序耗电量控制首要从下面3个方面抓起: 1.频繁的 ...

  2. css读书笔记4:字体和文本

    字体属性网页中的字体有3个来源:1.用户机器中安装的字体:2.保存在第三方网站上的字体.可以使用link标签把它们链接到页面中:3.保存在子集的web服务器上的字体.可以使用@font-face规则随 ...

  3. JSONObject和JSONArray使用

    1.所依赖JAR包 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: commons-lang.jar commons-beanutils.jar common ...

  4. Android 使用dagger2进行依赖注入(基础篇)

    0. 前言 Dagger2是首个使用生成代码实现完整依赖注入的框架,极大减少了使用者的编码负担,本文主要介绍如何使用dagger2进行依赖注入.如果你不还不了解依赖注入,请看这一篇. 1. 简单的依赖 ...

  5. 如何使用Vbox添加虚拟机

    简介 :vbox是oracle旗下的一个免费的虚拟机软件. 个人感觉操作方便,至少比VM要好用的多. 如果有已经制作好的 点击下一步: 下一步 找到之后 创建 look

  6. 杂谈:Servlet(2)

    Servlet的方法剖析: 1.service()方法里面做了什么? 2.doGet()与doPost()做了什么?应该怎么写? 回答 1.service()方法里面做了什么? 如果你的service ...

  7. hdu------(3549)Flow Problem(最大流(水体))

    Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tota ...

  8. JSCore的基本使用

    一.简单介绍 JSCore全称为JavaScriptCore,是苹果公司在iOS中加入的一个新的framework.该framework为OC与JS代码相互操作的提供了极大的便利.该工程默认是没有导入 ...

  9. NPOI相关

    总结一下工作中遇到的NPOI以及在ASP.NET MVC中的使用 http://www.cnblogs.com/fenglingyi/p/4750323.html

  10. 你需要知道的三个 CSS3技巧(转)

    1. 在CSS中用attr()显示HTML属性值 attr()功能早在CSS 2.1标准中就已经出现,但现在才开始普遍流行.它提供了一个巧妙的方法在CSS中使用HTML标签上的属性,在很多情况下都能帮 ...