webBrowser 清空cookie

来源:互联网 发布:东华大学网络教育平台 编辑:程序博客网 时间:2024/05/16 01:37
 [DllImport("wininet.dll", SetLastError = true)]
        private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
        //清空session
        public void ResetSession()
        {
            //Session的选项ID为42
            InternetSetOption(IntPtr.Zero, 42, IntPtr.Zero, 0);
        }
        //清空cookie
        public void ResetCookie()
        {
            ResetSession();
            if (webBrowser1.Document != null)
            {
                webBrowser1.Document.Cookie.Remove(0, webBrowser1.Document.Cookie.Length);
            
            }
            string[] theCookies = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
            foreach (string currentFile in theCookies)
            {
                try
                {
                    System.IO.File.Delete(currentFile);
                }
                catch (Exception ex)
                {
                }
            }
        }
0 0
原创粉丝点击