Cookie adds another record instead of replacing an existing value

I use the popular jquery cookie plugin to set session cookie value using javascript:

function ChangeLoginUser(sel) {
    var selectedUser = sel.options[sel.selectedIndex].value;
    $.cookie("LoginUser", selectedUser);
    location.reload(true); //refresh
}

This function is called after the user selects a site from the drop-down list with the global drop-down list.

  • Change the value on page 1 - cookie set CookieName = Value1.
  • Go to page2 - Cookie saved correctly
  • Change the dropdown value to value2. Fiddler now displays two cookies with the same name with both values, such as:
CookieName = value2
CookieName = value1

I do not understand why this is happening. I need to save only one cookie of this name. The new value should replace the old.

+1
source share
1

Ok. , cookie. URL- cookie . , :

$.cookie("LoginUser", selectedUser, { path: '/' });

, , :

$.cookie("LoginUser", selectedUser, { path: AppPath });

AppPath

<script type="text/javascript">
    var AppPath = '@Url.Content("~/")'
</script>
+1

All Articles