Sunday, October 4, 2009

how to clear cookies/cache for browser using C# .NET

using System.IO;
void clearIECache()
{
ClearFolder (new DirectoryInfo (Environment.GetFolderPath
(Environment.SpecialFolder.InternetCache)));
}

void ClearFolder (DirectoryInfo folder)
{
foreach (FileInfo file in folder.GetFiles())
{ file.Delete(); }
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{ ClearFolder(subfolder); }
}

public static void Main( )
{
new Test().clearIECache ();
}

4 comments:

  1. ll this be helpfull to clear cache of client browser

    ReplyDelete
  2. public static class SingleTon
    {
    public static void ClearCache()
    {
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);
    HttpContext.Current.Response.Cache.SetNoServerCaching();
    HttpContext.Current.Response.Cache.SetNoStore();
    }
    }
    And on page load use this..
    protected void Page_Load(object sender, EventArgs e)
    {
    SingleTon.ClearCache();
    }

    ReplyDelete
  3. It appear "Confirm Form Resubmission" when i click previous button of browser, and it will go to login page after i click on refresh browser of button.

    ReplyDelete
  4. i need for clearing history for chrome browser how to write
    (c# windows form app) just only one button i will click then clear the history how to?

    ReplyDelete