Tuesday, December 19, 2017

Cookies are being deleted

Leave a Comment

I have an asp.net mvc application and I have this strange thing that is happening and I don't know why.

Context:

I have a page that allows the user draw and edit images. This page has a feature that each 5 minutes, she made a ajax call to the server using jquery, saving the current state of the project on the database and another call to save an image of the project that is storage in a proper place.

Problem:

With the browser minimized, when this feature is launched, after the ajax call to the server, the cookie Customer is deleted. But when the chrome is maximized, this works fine.

Notes:

  1. This only happens when the browser is minimized
  2. This is happening, at least, in chrome and firefox.
  3. This is only happens on the production environment. On my local machine and on visual studio i cannot reproduce the issue
  4. The asp.net session cookie is mantainned

I know that is difficult for you to help only with this information, but, if you can give me clues it will be really helpful. I'm trying to expose the problem so we can match similar issues to find the best solution for this case.

Thank you in advance

[EDIT]:

I have some new about the issue:

  1. Using Chrome Version 63.0.3239.84 (Official Build) (64-bit);
  2. Firefox quantum 57.0 (64-bit);
  3. Contrary that I first thought, this is happens even if the browser is not minimized and precisely 3 mints after the page load (if I call the function)
  4. The cookie are not being deleted but the content of the cookie is: enter image description here
  5. This is a asp.net web application
  6. The console does not gives any errors
  7. The version of query is 2.1.3
  8. Follows the jquery call code:

    makeAjaxCall(ajaxData) { var localData = ajaxData.data ? ajaxData.data : {},     urlVariables = {};  localData.cmd = ajaxData.cmd;  var controlerURL = ajaxData.uploadUrl ? HelperJSViewBag.getValue("ajaxCAllUploadURL") : ajaxData.controller;  if (typeof ajaxData.data.urlVariables == "undefined")     ajaxData.data.urlVariables = [];  let editorVersion = ""; let forceEditorVersion = "";  if (typeof UrlParameters != "undefined") {     editorVersion = UrlParameters.getInstance().editorVersion;     forceEditorVersion = UrlParameters.getInstance().forceEditorVersion; } else if (typeof HLinks != "undefined") {     editorVersion = HLinks.getUrlVariable("editorVersion");     forceEditorVersion = HLinks.getUrlVariable("forceEditorVersion"); }  if (editorVersion.length > 0)     ajaxData.data.urlVariables.push({         name: "editorVersion",         value: editorVersion,     });  if (forceEditorVersion.length > 0)     ajaxData.data.urlVariables.push({         name: "forceEditorVersion",         value: forceEditorVersion,     });  if (typeof ajaxData.data.urlVariables != "undefined" && ajaxData.data.urlVariables.length > 0)     for (var i = 0; i < ajaxData.data.urlVariables.length; i++)         urlVariables[ajaxData.data.urlVariables[i].name] = ajaxData.data.urlVariables[i].value;  localData = this.fillLocalData(localData);  return $.ajax({     type: 'POST',     data: localData,     url: controlerURL + "?" + $.param(urlVariables),     success: function (data) {         try {             var result = JSON.parse(data),                 status = result.status;              delete result.status             switch (status) {                 case 1: ajaxData.sucess && ajaxData.sucess(result.data); break;                 case 2: ajaxData.insucess && ajaxData.insucess(ajaxData.errorHandler && ajaxData.errorHandler.handle && ajaxData.errorHandler.handle(result)); break;             }         }         catch (ex) {             ajaxData.insucess && ajaxData.insucess(ajaxData.errorHandler && ajaxData.errorHandler.handle && ajaxData.errorHandler.handle(ex));         }     },     error: function (data) {         ajaxData.insucess && ajaxData.insucess(ajaxData.errorHandler && ajaxData.errorHandler.handle && ajaxData.errorHandler.handle(data));     } }); } 

2 Answers

Answers 1

I would like to see your code on the ASP.NET side, but without that, I can only guess: perhaps check to see if you are setting a cookie expiration date? Here is an example of a cookie that is created with 1 day expiration:

Dim myCookie As HttpCookie = New HttpCookie("Customer") myCookie.Expires = Now.AddDays(1) Response.Cookies.Add(myCookie) 

If you omit myCookie.Expires property, the cookie "will expire when the user session expires", ref. https://msdn.microsoft.com/en-us/library/78c837bd.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Answers 2

  1. you can increase the expiration time of your Cookies (Within the code where you are creating cookies).

  2. You can use localStorage in your code instead of Cookies to hold the value.

For examlpe localStorage.setItem to set value and localStorage.getItem to get the value from local storage.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment