zoukankan      html  css  js  c++  java
  • 关于用户退出,点击浏览器后退仍可回到原来页面

    解决方案1:禁用缓存,前一次使用的方法,在电脑上各浏览器都没问题,但在ipad、安卓手机上仍有问题

     asp.net方法

    因为客户端缓存了页面

    1 Response.Buffer = true;
    2 Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
    3 Response.Expires = 0;
    4 Response.CacheControl = "no-cache";

    在你的page_load里面加上上面的代码,强制不缓存页面

    你退出的话,要把当前会话ID(sessionid)清掉

    强制登录,需要在页面上判断session是否存在,不存在就跳回到登录页面,存在就继续访问

    HTML方法

            <HEAD>
            <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
            <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
            <META HTTP-EQUIV="Expires" CONTENT="0">
            </HEAD>

    解决方案2:禁用浏览器后退键 javascript: window.history.forward(1); 结果和方案一一样的结果,pad上没效果

    解决方案3:Response.Write("<script>window.location.replace('login.aspx')</script>");仍旧可以后退,感觉还不如1、2,但是在前台加个onclick事件,不涉及表单提交,竟然可以,由此就到方案4

    解决方案4:用ajax,在ajax页面里将session清空,然后在现在的页面加js

    function logout(isLogout) {
                if (isLogout != "") {
                    $.ajax({
                        url: "ajax/logout.aspx",
                        data: "code=" + encodeURI(isLogout), cache: false,
                        datatype: "html",
                        success: function (context) {
                            LogoutReturn(context);
                        }
                    });
                }
                else {
                    return "Error";
                }
            }
    
            function LogoutReturn(context) {
                if (context == "success") {
                    location.replace('login.aspx');
                }
            }

    好了,算是解决了问题。

    参考:http://bbs.csdn.net/u/20110519/15/bda40bee-100c-4054-a3d8-eb8b2ff2ee68.html

  • 相关阅读:
    C. Karen and Game
    BZOJ2134: 单选错位
    BZOJ3562: [SHOI2014]神奇化合物
    BZOJ1084: [SCOI2005]最大子矩阵
    BZOJ5039: [Jsoi2014]序列维护
    BZOJ1798: [Ahoi2009]Seq 维护序列seq
    BZOJ3932: [CQOI2015]任务查询系统
    BZOJ3339: Rmq Problem
    BZOJ3585: mex
    BZOJ4196: [Noi2015]软件包管理器
  • 原文地址:https://www.cnblogs.com/caixiaofeng/p/3479438.html
Copyright © 2011-2022 走看看