获得cookie方法:
   function GetCookie(sName) {
            var aCookie = document.cookie.split("; ");
            alert(aCookie);
            for (var i = 0; i < aCookie.length; i++) {
                var aCrumb = aCookie[i].split("=");
                if (sName == aCrumb[0])
                    return unescape(aCrumb[1]);
            }
            return null;
        }     调用js方法  :  var hadValidCode = GetCookie("ValidateCodes");
是ValidateCode.aspx.cs页面写的,在登录页载入ValidateCode.aspx.cs和cookie方法   :Response.Cookies.Add(new HttpCookie("ValidateCodes", code));
但是获得的cookie值一直是空的

解决方案 »

  1.   

    如果在前台调用js获取cookies,后台cs写入cookie,这不就涉及到一个顺序问题嘛,程序会先执行js,这时还没执行到后台,当然就获取不到cookie了。
      

  2.   

    Lz还是用jQuery cookies写入和读取吧。http://blog.csdn.net/zgxasd/article/details/6799532
      

  3.   

    你得确定你的code是否有值,如果有值还获取不到的话 清清缓存试试
      

  4.   

    var hadValidCode = GetCookie("ValidateCodes");
    你这是在后台写的?后台能直接这样调用页面的JS?
      

  5.   

    jquery.cookie.js:http://pan.baidu.com/share/link?shareid=1129064762&uk=2266385818
      

  6.   

    你这个ValidateCode.aspx是不是用在img的src中的??
      

  7.   

    /* cookie */
    function cookie(key, value, options) {
        // key and value given, set cookie...
        if (arguments.length > 1 && (value === null || typeof value !== "object")) {
            options = jQuery.extend({}, options);        if (value === null) {
                options.expires = -1;
            }        if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }        return (document.cookie = [
                 encodeURIComponent(key), '=',
                 options.raw ? String(value) : encodeURIComponent(String(value)),
                 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                 options.path ? '; path=' + options.path : '',
                 options.domain ? '; domain=' + options.domain : '',
                 options.secure ? '; secure' : ''
             ].join(''));
        }    // key and possibly options given, get cookie...
        options = value || {};
        var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
        return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    };存储:cookie(cookie的名字, cookie的值, { expires: 7 });
    调用:var cookie_value = cookie(cookie的名字);
    希望可以帮到你哦!!!
      

  8.   

    谢谢各位亲们,找到问题所在了,是web.config配置的问题,web.config把cookie禁用了,只要 写成这样  <httpCookies httpOnlyCookies="false" requireSSL="false" domain=""/>就行了