今天在web开发中,如果想在浏览器后退到登入界面后就清空session,来防止前进的时候不会自动登入。

当当清空session 是不够的,还要考虑到页面缓存的冬。

在asp.net下

 

       protected void Page_Load(object sender, EventArgs e)
        {
            Session.Clear();
            cache.ClearAll(); //这里的cache是自定的缓存清除类
        }

 

在接受的主页面也要加上清空缓存操作,

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "No-Cache");
        }

以上这种方法 只能局限于 ie浏览器中使用。

在其他浏览器需要用到  $.ajaxSetup

      <script type="text/javascript" >
            $(document).ready(function() {
                $.ajaxSetup({
                    cache: false //设置成false将不会从浏览器缓存读取信息
                });
            });
        </script>

在浏览其中加入$.ajaxSetup 就能控制不会从浏览器缓存读取数据。就能轻松解决这问题。

 

相关文章:

  • 2021-08-08
  • 2021-07-14
  • 2022-01-11
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2021-06-04
  • 2021-12-01
  • 2022-02-08
相关资源
相似解决方案