0

I've this:

// connect to MemberHub
function connect() {

    // get unique id cookie
    var uid = $.cookie('UniqueID', { path: '/' });

    member.server.connect(uid).done(function (result) {
        if (result.msg == 'success') {
            // notify user  
            $('#log').append($('<li>', { html: 'Connected to MemberHUB' }));
        }
    });
}

Each time I try to read cookie it creates same cookie instead of read it.

Update: Here is how I assign cookies:

    public static HttpCookie Create(string name, string value, 
        DateTime expires, HttpContextBase httpContext)
    {
        var cookie = new HttpCookie(name)
        {
            Value = value,
            Expires = expires,
            Secure = true,
            HttpOnly = false,
            Path = "/"
        };

        httpContext.Response.Cookies.Add(cookie);
        return cookie;
    }

Any advice will be helpful.

Saber Amani
  • 6,409
  • 12
  • 53
  • 88

1 Answers1

1

$.cookie is only read access if no other parameters (but the cookie's name) are supplied to the method [See the source]

If you're interested in reading it, just supply $.cookie('UniqueID') and remove the second parameter.

As an FYI, path (and other cookie properties) are only relevant when assigning a value, not retrieving. In other words, you don't need to supply path:'/' to get cookies that are applied to that path, document.cookie should natively perform that check.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • Thanks for your reply, but when I remove the `Path` I get null value for cookie. – Saber Amani Aug 19 '13 at 12:18
  • And how are you assigning it? The value is the second parameter with prongs being the third. – Brad Christie Aug 19 '13 at 12:32
  • @SaberAmani: you've confirmed it's being assigned at the client level? I don't see any reason why you can't access it other than if there was nothing to access in the first place. – Brad Christie Aug 19 '13 at 13:14