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);
}

}

}

If you have better solution, just tell me !

0 comments: