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:
.
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=/'; }
Advertisement
Answer
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.