"Summary" 6 ways to clear WebBrowser cookie/session

Source: Internet
Author: User

Here are 6 ways I've tested 6 cookies to clear WebBrowser:

            //method One: Call Wininet.dll to clear cookies (recommended)Suppresswininetbehavior (); //Method Two: Delete the user login information, this is equivalent to the browser logout function, using the features IE comes with (recommended)HTMLDocument document =WB.            Document; Document. ExecCommand ("Clearauthenticationcache",false,NULL); //Method Three: Delete the native cookie This method pops up the pop-up box of IE clear Cookie//Temporary Internet Files (Temporary Internet file)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 8//Cookies//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2//history (historical record)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1//Form. Data (form)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess//passwords (password)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess//Delete All (remove All)//ShellExecute (IntPtr.Zero, "open", "rundll32.exe", "Inetcpl.cpl,clearmytracksbyprocess 2", "", Showcommands.sw_ HIDE);ShellExecute (IntPtr.Zero,"Open","rundll32.exe","inetcpl.cpl,clearmytracksbyprocess 255","", Showcommands.sw_hide); //method Four: The use of WebBrowser self-coookie method (not recommended, clear the session, measured invalid)Wb. Document.Cookie.Remove (0, (WB. Document.Cookie.Count ()-1)); //method Five: Use JS to clear the cookie (not recommended, clear the session)Wb. Navigate ("javascript:void (function () {var a,b,c,e,f;f=0;a=document.cookie.split ('; '); for (e=0;e<a.length&&a[e];e++) {f++;for (b= '. ') +location.host;b;b=b.replace (/^.:%5c.| [^%5C.] +)/, ') {for (C=location.pathname;c;c=c.replace (/.$/, ')) {document.cookie= (a[e]+ '; domain= ' +b+ '; path= ' +c+ '; Expires= ' +new date (new Date ()). GetTime () -1e11). toGMTString ());}}}) ())"); //var a,b,c,e,f; //f=0; //A=document.cookie.split (';            ‘); //b= '. ' + ' baidu.com ';            ////b= '. ' + ' www.baidu.com ';            //For (e=0;e<a.length;e++) {//    //b= '. '            +location.host; //B=b.replace (/^.:%5c.| [^%5C.]            +)/, '); //C=location.pathname; //C=c.replace (/.$/, "); //ck = a[e]+ '; domain= ' +b+ '; path= ' +c+ '; expires= ' +new date (new Date ()). GetTime () -1e11). toGMTString (); //console.log (CK); //Document.cookie=ck; //}            //method Six: Use InternetSetCookie to assign a null value to a cookie (not recommended)//You can also assign a null value to this cookie: InternetSetCookie//InternetSetCookie ("http://. qq.com/", NULL," uin=; path=/; Domain=qq.com ");

Method One:
[System.Runtime.InteropServices.DllImport ("Wininet.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError =true)]         Public Static extern BOOLInternetSetOption (intHinternet,intDwoption, IntPtr lpbuffer,intdwbufferlength); /// <summary>        ///use InternetSetOption operation Wininet.dll to clear cookies in WebBrowser/// </summary>        Private Static unsafe voidSuppresswininetbehavior () {/*SOURCE:http://msdn.microsoft.com/en-us/library/windows/desktop/aa385328%28v=vs.85%29.aspx* Internet_option_suppress_behavior (Bayi): * A General purpose OPTION which is used                 To suppress behaviors on a process-wide basis.                 * The lpbuffer parameter of the function must is a pointer to a DWORD containing the specific behavior to suppress.                 * This option cannot is 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. */            intoption = (int)3/*internet_suppress_cookie_persist*/; int* Optionptr = &option; BOOLSuccess = InternetSetOption (0,Bayi/*Internet_option_suppress_behavior*/,NewINTPTR (OPTIONPTR),sizeof(int)); if(!success) {MessageBox.Show ("Something went wrong! Clear Cookie failed!"); }        }
Method Two:

That's all I can say:

// Method Two: Delete the user login information, this is equivalent to the browser logout function, using the features IE comes with (recommended)            HTMLDocument document = wb. Document;            Document. ExecCommand ("clearauthenticationcache"falsenull);
Method Three:
 //Method Three: Delete the native cookie This method pops up the pop-up box of IE clear Cookie//Temporary Internet Files (Temporary Internet file)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 8//Cookies//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2//history (historical record)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1//Form. Data (form)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess//passwords (password)//RunDll32.exe inetcpl.cpl,clearmytracksbyprocess//Delete All (remove All)//ShellExecute (IntPtr.Zero, "open", "rundll32.exe", "Inetcpl.cpl,clearmytracksbyprocess 2", "", Showcommands.sw_ HIDE);ShellExecute (IntPtr.Zero,"Open","rundll32.exe","inetcpl.cpl,clearmytracksbyprocess 255","", showcommands.sw_hide);
ShellExecute Method:
     Public enumShowcommands:int{sw_hide=0, SW_SHOWNORMAL=1, Sw_normal=1, sw_showminimized=2, sw_showmaximized=3, Sw_maximize=3, Sw_shownoactivate=4, Sw_show=5, Sw_minimize=6, Sw_showminnoactive=7, Sw_showna=8, Sw_restore=9, Sw_showdefault=Ten, Sw_forceminimize= One, Sw_max= One} [DllImport ("Shell32.dll")]        Static externINTPTR ShellExecute (INTPTR hwnd,stringLpoperation,stringLpfile,stringLpparameters,stringLpdirectory, Showcommands nShowCmd);

Method Four:
  // method Four: The use of WebBrowser self-coookie method (not recommended, clear the session, measured invalid)            Wb. Document.Cookie.Remove (01));
Method Five:
 //method Five: Use JS to clear the cookie (not recommended, clear the session)Wb. Navigate ("javascript:void (function () {var a,b,c,e,f;f=0;a=document.cookie.split ('; '); for (e=0;e<a.length&&a[e];e++) {f++;for (b= '. ') +location.host;b;b=b.replace (/^.:%5c.| [^%5C.] +)/, ') {for (C=location.pathname;c;c=c.replace (/.$/, ')) {document.cookie= (a[e]+ '; domain= ' +b+ '; path= ' +c+ '; Expires= ' +new date (new Date ()). GetTime () -1e11). toGMTString ());}}}) ())"); //var a,b,c,e,f; //f=0; //A=document.cookie.split (';            ‘); //b= '. ' + ' baidu.com ';            ////b= '. ' + ' www.baidu.com ';            //For (e=0;e<a.length;e++) {//    //b= '. '            +location.host; //B=b.replace (/^.:%5c.| [^%5C.]            +)/, '); //C=location.pathname; //C=c.replace (/.$/, "); //ck = a[e]+ '; domain= ' +b+ '; path= ' +c+ '; expires= ' +new date (new Date ()). GetTime () -1e11). toGMTString (); //console.log (CK); //Document.cookie=ck; //}

Will WB. Navigate ("javascript:void () (function () {... } content into the following commented out code, write good you want to clear cookier domain and then you can clear, but not clear the session, this is from the foreign site appears, the actual invalid!

Method Six:
// method Six: Use InternetSetCookie to assign a null value to a cookie (            not recommended) // You can also assign a null value to this cookie            : InternetSetCookie // InternetSetCookie ("http://. qq.com/", NULL, "uin=; path=/; Domain=qq.com ");

About InternetSetCookie This method on your own online search.

"Summary" 6 ways to clear WebBrowser cookie/session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.