zoukankan      html  css  js  c++  java
  • 静态页动态读写Cookie

    首页登录  代码如下

    //存入cookie  
                HttpCookie newCookie = new HttpCookie("User");  
                newCookie.Expires.AddMinutes(30);//设置时间  
                newCookie.Values.Add("uid","001");  
                newCookie.Values.Add("username","leo li");  
                Response.AppendCookie(newCookie); 

    html   代码如下

    <html>  
    <title>测试</title>  
    <mce:script type="text/javascript" language="javascript"><!--  
        function GetCookie(sMainName, sSubName) {  
            var sCookieName = sMainName + "=";  
            var sSubCookieName = (sSubName) ? sSubName + "=" : null;  
            var sCookie;  
            var sWholeCookie = document.cookie;  
      
            var nValueBegin = sWholeCookie.indexOf(sCookieName);  
            if (nValueBegin != -1) {  
                var nValueEnd = sWholeCookie.indexOf(";", nValueBegin);  
                if (nValueEnd == -1)  
                    nValueEnd = sWholeCookie.length;  
      
                var sValue = sWholeCookie.substring(nValueBegin + sCookieName.length, nValueEnd); //获得Cookie值  
      
                if (sSubCookieName)//多值Cookie  
                {  
                    var nSubValueBegin = sValue.indexOf(sSubCookieName);  
                    if (nSubValueBegin != -1) {  
                        var nSubValueEnd = sValue.indexOf("&", nSubValueBegin);  
                        if (nSubValueEnd == -1)  
                            nSubValueEnd = sValue.length;  
                        var sSubValue = sValue.substring(nSubValueBegin + sSubCookieName.length, nSubValueEnd); //获得指定的子键值  
                        return unescape(sSubValue);  
                    }  
                }  
                if (!sSubCookieName)  
                    return unescape(sValue);  
            }  
            return null;  
        }  
        function a() {  
            if (GetCookie('User', 'name') != null) {  
                document.write('用户名:' + GetCookie('User', 'name') + '<a href="/logout.aspx" mce_href="logout.aspx">注销</a>');  
            }  
            else {  
                document.write('<a href="/login.aspx" mce_href="login.aspx">登录</a> <a href="/reg.aspx" mce_href="reg.aspx">注册</a>');  
            }  
        }  
    // --></mce:script>  
    <head>  
    </head>  
    <body onload="a()">  
    </body>  
    </html>  

    转载至 : http://blog.csdn.net/lilin8905/article/details/5568327

  • 相关阅读:
    RDLC报表中浮点型设置精度设置小数位位数
    C# 设置DateTime类型的变量值等于Null
    我的2011就这样混掉了
    RDLC报表改动的注意事项之增加字段和参数
    (分享)C# 绘制统计图(柱状图, 折线图, 扇形图)
    C#实现Winform自定义半透明遮罩层
    C#中判断网络连接的状态
    su 和 sudo、su root和su root 区别
    嵌入式系统软件优化方法
    ARM开发步步深入之定时加速
  • 原文地址:https://www.cnblogs.com/yudishow/p/4288387.html
Copyright © 2011-2022 走看看