Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Writing cookie seems to lose its original value

I seem to be having trouble storing a cookie and then reading back its value.

The cookie I’m writing is Name = TransloadingInventory-filter, Value = Consignee:HALLIBURTON ENERGY SERVICES::ProductCategory:1::Product:2.

But as soon as I write this value, the browser shows the current value for this cookie is Consignee:::ProductCategory:::Product:.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In addition, I don’t know if this is related but when I try and read the Request.Form in ASP.NET, I get the exception Incorrect Content-Type:.

Is there an issue putting colons in cookie values? Can someone suggest some troubleshootng steps? Here’s the function I’m using to write the cookie.

function setCookie(name, value, days) {
    var expires = ';'
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = '; expires=' + date.toUTCString();
    }
    document.cookie = name + '=' + value + expires + '; path=/';
}

>Solution :

The code you provided works for me in Chrome with setCookie('TransloadingInventory-filter', 'Consignee:HALLIBURTON ENERGY SERVICES::ProductCategory:1::Product:2', 1).

Further, https://stackoverflow.com/a/1969339 references (and includes source material for) which characters are valid in cookie names/values which includes :.

Regarding incorrect content-type, check the network tab in debugger (or if you have access to the raw HTTP request) to see if a content-type header is being sent.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading