How to delete the cookies create by a WebBrowser? RRS feed

  • 問題

  • Hello,

    I use a WebBrowser (C# .Net 2.0) and i don't know how i can delete the cookies created by the WebBrowser?

    Thanks for your help!
    2006年10月20日 上午 10:03


  • the WebBrowser uses IE as its core engine, so pretty much you have IE embedded in your application (all stripped out to the very core) so if you delete cookes in the webbrowser control, you are deleting cookies for the main IE application/webbrowser.

    if you still want to delete the cookies, then you need to use the File.Delete() method. Example:



    be warned, you may have access denied (UnAuthorizedException) or IOException when deleting a file that cannot be deleted, so place a try catch block around it.

    You could also go through EACH cookie found in the cookie folder and then delete it and move on if there is an exception:

    string[] theCookies = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies))


    foreach(string currentFile in theCookies)






       catch(Exceptions...........) { ... }


    2006年10月20日 下午 01:50
  • Thank you.

    But why my cookie is stored for my application but not used by IE?

    I a use a WebBroser to go to Hotmail.com and set to store my mail and my password, if i close the application and run it again, hotmail don't ask me again my password.

    But when i open IE hotmail ask me my password! It's not the same cookie?
    There is a different cookie by application?

    2006年10月20日 下午 02:19
  • interesting.

    you can clear the cookie when the document has been loaded into your webbrowser control but no idea if this will remove it from the application/cookie cache:

    this.theWebBrowserControl.Document.Cookie = null;


    2006年10月20日 下午 02:24
  • Ok now how I can add cookie to WebBrouser Control (this.theWebBrowserControl)?
    I try
    webBrowser.Document.Cookie += "ty=wert;"

    but it not work.

    2009年7月22日 上午 11:06
  • Heh to add cookie write

    webBrowser.Document.Cookie = "ty=wert;"

    without + :-)
    2009年7月22日 上午 11:51
  • you can remove page cookies as

    int count = webBrowser1.Document.Cookie.Length; 

    • 已編輯 ps008 2012年4月13日 下午 04:56
    2012年4月13日 下午 04:53
  • Its working on 7, windows 10 IE 11 not deleting cookies on my app which is developed on c#.Can you please help me to found this?
    2018年2月8日 上午 11:38