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

When cookie has some values, it cannot be read back

When I save a cookie with the following value, it works fine:

TransloadingInventoryFilter=Product:2

When I save a cookie with the following value, it works fine:

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

TransloadingInventoryFilter=ProductCategory:1::Product:2

But when I save a cookie with the following value, it doesn’t work:

TransloadingInventoryFilter=Consignee:HALLIBURTON ENERGY SERVICES::ProductCategory:1::Product:2

My browser correctly shows this as the cookie value. But when my page loads, Request.Form throws an InvalidOperationException: Incorrect Content-Type: .

And the Request.Cookies collection has all my cookies except TransloadingInventoryFilter, which is missing.

The following cookie value also does not work:

TransloadingInventoryFilter=Consignee:HALLIBURTON ENERGY SERVICES

I’ve spent hours on this issue. I cannot understand why this one cookie value does not work. And I don’t know what else to try.

Note that I’m reading cookies using ASP.NET, but I’m writing my cookies using JavaScript and the following function.

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

Can anyone offer some suggestions?

>Solution :

Spaces are not allowed in cookie values, refer to this question What are allowed characters in cookies? for more details

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