C # ways to clear cookie caching in WebBrowser _c# tutorial

Source: Internet
Author: User

The example in this article describes how C # clears the cookie cache in WebBrowser. Share to everyone for your reference, specific as follows:

Recently used C # to write a program, with a form of WebBrowser to log on the site, but WebBrowser have cookie cache, the second landing WebBrowser is still the first time after the state, So to clear the WebBrowser cookie cache.

Find a piece of code available on the 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 (Bayi): * A General purpose OPTION This is used to supp 
  Ress 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 Specifi
  ed them as persistent.
  * Version:requires Internet Explorer 8.0 or later.
  * * 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!>?");

 }
}

Read more about C # Interested readers can view the site topics: "C # Common control usage Tutorial", "C # Data structure and algorithm tutorial", "C # object-oriented Program design Introductory Course" and "C # Programming Thread Usage Skills Summary"

I hope this article will help you with C # programming.

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.