我想在按钮点击时使用asp.net应用程序清除客户端所有浏览器的缓存。当我们从visual studio运行时,它的工作正常。但问题是当我们将应用程序托管到IIS中时,它变得无法正常工作。
这是代码,我用来清除客户端浏览器的缓存
[WebMethod]
public static string DoClearCache()
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Session["AEmail"] = null;
HttpContext.Current.Session.Clear();
ClearCaches();
clearchachelocalall();
return null;
}
public static void ClearCaches()
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);
//HttpContext.Current.Response.Cache.SetNoServerCaching();
//HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.Cookies.Clear();
HttpContext.Current.Request.Cookies.Clear();
}
private static void clearchachelocalall()
{
string GooglePath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Google\Chrome\User Data\Default\";
string MozilaPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Mozilla\Firefox\";
string Opera1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Opera\Opera";
string Opera2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Opera\Opera";
string Safari1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Apple Computer\Safari";
string Safari2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Apple Computer\Safari";
string IE1 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Intern~1";
string IE2 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\History";
string IE3 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Local\Microsoft\Windows\Tempor~1";
string IE4 = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Microsoft\Windows\Cookies";
string Flash = Environment.GetEnvironmentVariable("USERPROFILE") + @"\AppData\Roaming\Macromedia\Flashp~1";
//Call This Method ClearAllSettings and Pass String Array Param
ClearAllSettings(new string[] { GooglePath, MozilaPath, Opera1, Opera2, Safari1, Safari2, IE1, IE2, IE3, IE4, Flash });
}
public static void ClearAllSettings(string[] ClearPath)
{
foreach (string HistoryPath in ClearPath)
{
if (Directory.Exists(HistoryPath))
{
DoDelete(new DirectoryInfo(HistoryPath));
}
}
}
public static void DoDelete(DirectoryInfo folder)
{
try
{
foreach (FileInfo file in folder.GetFiles())
{
try
{
file.Delete();
}
catch
{ }
}
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{
DoDelete(subfolder);
}
}
catch
{
}
}
我真的在寻找你宝贵的建议。