Recently wrote a program in c#,Use a webbrowser in a form to log in to the website,However, webbrowser has a cookie cache. When the second login, webbrowser is still in the state after the first login.So clear the cookie cache of webbrowser.

Find a piece of code available on 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!"?");
  • Previous Dictionary usage sharing in python
  • Next Graphical triangle relationship between prototype, prototype, and constructor