Thursday, July 9, 2009

Deleting Session Cookie in Webbrowser control.



We know that many websites are using cookies for storing some user data in browser to improve user experience.

C#.net is having webbrowser control for creating applications useful for automatically navigating/crawling websites.

It will be required to delete these cookies in webbrowser control when using it for different set of user logins.

Below C# function will be useful for deleting the cookie for IE (Internet Explorer) browser. As webbrowser control will share the cookie with IE, this code can be used for deleting webbrowser control cookie.

I heard that cookie will be stored somewhere temporarily also, and this function won't delete it. But I am not sure about. If anyone know more details about this temporary cookie you can share it here.



private void deletecookie()
{
string[] theCookies = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));

foreach(string currentFile in theCookies)
{

try
{

System.IO.File.Delete(currentFile);

}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}


}


}



More Articles...

2 comments:

Anonymous said...

Warning: This DOES NOT work. It cannot delete the index.dat file so all cookies are not deleted.

maeishoj said...

not true! this DOES work like a charm!



Thanks for visiting our blog


twitterrss facebook linkedin YouTube subscribe


Subscribe via email

Enter your email address: