源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#清除WebBrowser中Cookie缓存的方法

  • 时间:2022-06-07 07:06 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#清除WebBrowser中Cookie缓存的方法
本文实例讲述了C#清除WebBrowser中Cookie缓存的方法。分享给大家供大家参考,具体如下: 最近用C#写一个程序,用一个窗体中的WebBrowser来登陆网站,但是WebBrowser有cookie缓存,第二次登陆的时候WebBrowser仍然是第一次登陆后的状态,所以要清除WebBrowser的cookie缓存。 在stackoverflow上找到一段可用的代码:
[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 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 !>?");
  }
}

更多关于C#相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/165.htm]C#常见控件用法教程[/url]》、《[url=http://www.1sucai.cn/Special/116.htm]C#数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/478.htm]C#面向对象程序设计入门教程[/url]》及《[url=http://www.1sucai.cn/Special/227.htm]C#程序设计之线程使用技巧总结[/url]》 希望本文所述对大家C#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部