Answer the question
In order to leave comments, you need to log in
C# How to clear all cookies in WebBrowser?
There are options to switch the browser by calling the cleanup javascript (the parser ate the code), but this code only works for one specific site and then every other time.
There is also an option to clean the directory
string Path = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
try
{
System.IO.Directory.Delete(Path, true);
}
catch (Exception)
{
}
Process.Start("cmd.exe", "/C RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255");
Answer the question
In order to leave comments, you need to log in
Indeed, the line deleted cookies:
browser.Document.Cookie = name +"=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
which added another relatively pointless way to my treasury of silly ways to delete cookies.
Hm.
all nonsense, here is the working code for VK, i.e. api functions are 100% reliable, the downside is that you need to understand how to work with InternetGetCookie:
InternetSetCookie(" m.vk.com ", "remixsid", ""); //for example, clear authorization in VK
for specifically for each site, I think it's easy to guess
try{
foreach (Cookie c in Core.ActClient.CookieContainer.GetCookies(new Uri(" m.vk.com "))){
InternetSetCookie(" m.vk .com ",c.Name, "");
}
}catch{}
[DllImport("wininet.dll", CharSet = CharSet.Auto,
string lpszUrlName,
string lpszCookieName,
StringBuilder lpszCookieData,
[MarshalAs(UnmanagedType.U4)]
ref int lpdwSize
);
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(
string lpszUrlName,
string lpszCookieName,
string lpszCookieData
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question