在Global.asax.cs文件中的Application_BeginRequest方法中添加以下代码以覆盖或删除缓存控制和Pragma头:
//覆盖或删除缓存控制和Pragma头 HttpContext.Current.Response.Headers.Remove("Cache-Control"); HttpContext.Current.Response.Headers.Remove("Pragma"); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
这段代码会在每个请求开始时调用,并删除或覆盖缓存控制和Pragma头,确保响应不会被缓存。
代码示例:
protected void Application_BeginRequest() { //覆盖或删除缓存控制和Pragma头 HttpContext.Current.Response.Headers.Remove("Cache-Control"); HttpContext.Current.Response.Headers.Remove("Pragma"); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); }