每当我在asp.net mvc中调用我的服务时,IE 9就会在其浏览器中缓存以前的数据,因此我的新更改不会反映在代码中。 请告诉我如何从IE 9中删除此自动缓存。
请帮帮我。
答案 0 :(得分:0)
您可以在URI中传递一个新参数,如timestamp,这将使每个调用成为唯一的url调用,因此IE 9不会对其进行缓存。 或者如果您使用的是Asp.net MVC,那么您可以在global.asax文件中进行更改,以便在浏览器级别切换缓存。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
// HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, tokenId");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}