views:

721

answers:

2

How can I set and delete cookies for a domain in webbrowser control without using Javascript (which doesn't allow to set / delete cookies without navigating to the website first.)

A: 

You can't delete cookies for a domain other than the domain of the current site.

To do what you are asking requires you have access to the machine (i.e. toolbar installed). Even then it's kludgy.

The only exception is if you are on a domain where the cookie is using the * wildcard, for example *.stackoverflow.com. If you change a cookie with the wildcard, then all the child sub domains (i.e. blog.stackoverflow.com) will have access and see the change that was made to the cookie.

Chuck Conway
From "Webrowser Control", this is not a web application it's Winforms.
dr. evil
+1  A: 

IE Uses WinInet functions for networking so you can use WinInet's cookie functions to change the cookie. Update: The requirement demands per-process setting. Since the cache folder location is not stored in IE settings registry key IDocHostUIHandler2::GetOverrideKeyPath won't work. I don't know a way to customize the cookie folder location at the process level except to hook all WinInet APIs (and stuck with updating application to accommodate future WinInet APIs).

Sheng Jiang 蒋晟
Isn't that for whole IE? I don't want to delete users' browser cookies for IE, it should be something only for the current application's hosted web control. Correct me if I'm wrong.
dr. evil
If you want to isolate your application's cookies you need to override the Cache directory registry setting via IDocHostUIHandler2::GetOverrideKeyPath
Sheng Jiang 蒋晟
I'm not positive that the GetOverrideKeyPath trick would even work.You'll want to use InternetSetCookieEx either way.
EricLaw -MSFT-
Yes, you are right, the IE cache folder setting isn't under IE settings. It is under shell folder settings.
Sheng Jiang 蒋晟