简体   繁体   English

清除Web浏览器Cookie Winforms C#

[英]Clear web browser cookies winforms C#

如何清除Web浏览器控件Winforms C#的cookie,有什么方法可以在Winforms Web浏览器控件中有问题地清除cookie

You can disable cache (including cookies) before navigating to the site. 您可以在导航到站点之前禁用缓存(包括cookie)。 To do so, you can use InternetSetOption API function and set the value of INTERNET_OPTION_SUPPRESS_BEHAVIOR(81) option to INTERNET_SUPPRESS_COOKIE_PERSIST(3) value. 这样做,您可以使用InternetSetOption API函数并将INTERNET_OPTION_SUPPRESS_BEHAVIOR(81)选项的值设置为INTERNET_SUPPRESS_COOKIE_PERSIST(3)值。

Example

The following example, works like starting a new session. 以下示例的工作方式类似于开始新的会话。 While I've logged in to the outlook.com on my machine, but when I open this application and browse outlook.com after disabling cookies and cache, it works like starting a new session and I need to login to outlook.com: 虽然我已经在计算机上登录了outlook.com ,但是在禁用Cookie和缓存后打开此应用程序并浏览outlook.com ,它的工作方式类似于开始一个新会话,我需要登录到Outlook.com:

//using System.Runtime.InteropServices;
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption,
    IntPtr lpBuffer, int dwBufferLength);
private void Form1_Load(object sender, EventArgs e)
{
    var ptr = Marshal.AllocHGlobal(4);
    Marshal.WriteInt32(ptr, 3);
    InternetSetOption(IntPtr.Zero, 81, ptr, 4);
    Marshal.Release(ptr);
    webBrowser1.Navigate("https://outlook.com");
}

To find more information about these flags, take a look at Windows Internet Option Flags . 要查找有关这些标志的更多信息,请查看Windows Internet Option标志

Note: You can find a VB.NET version of this answer, here in my other post. 注意:您可以找到这个答案的VB.NET版本, 在这里我的其他职位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM