Arunesh
Arunesh

Reputation: 297

Cookies get cleared during page reload in asp.net

I am setting the cookies in asp.net like this

      obj.opts.on('click', function () {
                var opt = $(this);
                obj.val = opt.text();
                obj.index = opt.index();
                obj.namePlaceholder.text(obj.val);
                obj.idPlaceholder.val(opt.attr('id'));
                document.cookie = "CityID=" + opt.attr('id');
                setCookie("CityID", DateTime.Now, 365);
                window.location.href = window.location.href;

and when I debug the value of cookies in serverside and every time it gets cleared. I am ckecking cookies like this

        if (Response.Cookies["CityID"].Value == null)
        {
           .....
        }

everi time this condition satisfies. any help to retain the cookies will surele be appreciated.

Upvotes: 1

Views: 1481

Answers (1)

Patrick
Patrick

Reputation: 6958

Without seeing more of the code, my first guess would be you want to look at Request.Cookies and not Response.Cookies.

Upvotes: 2

Related Questions