Home > Enterprise >  When cookie has some values, it cannot be read back
When cookie has some values, it cannot be read back

Time:08-13

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:

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?

CodePudding user response:

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

  • Related