Cookies are deleted

I have an asp.net mvc application and I have this weird thing that happens and I don't know why.

Context:

I have a page that allows the user to draw and edit images. On this page there is a function that makes an ajax call for the server every 5 minutes using jquery, saving the current state of the project in the database and another call to save the image of the project storing it in the right place.

Problem:

When the browser is minimized when this function is launched, after calling ajax to the server, the cookie client is deleted. But when chrome maximizes, it works great.

Notes:

  • This only happens if the browser is minimized.
  • This happens, at least in chrome and firefox.
  • This only happens in a production environment. On my local machine and in the visual studio, I cannot reproduce the problem.
  • Asp.net session mantainned cookie

I know that it’s difficult for you to help only with this information, but if you can give me tips, it will be very useful. I am trying to identify a problem so that we can match similar problems to find the best solution for this case.

Thank you in advance

[EDIT] :

I have some new problems:

  • Using Chrome version 63.0.3239.84 (official build) (64-bit);
  • Firefox quant 57.0 (64-bit);
  • Unlike what I thought at first, this happens even if the browser is not minimized and exactly 3 mints after the page loads (if I call the function)
  • The cookie is not deleted, but the contents of the cookie: enter image description here
  • This is an asp.net web application.
  • The console does not give any errors.
  • Request Version 2.1.3
  • Executes 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)); } }); } 
+5
source share
2 answers

I would like to see your code on the ASP.NET side, but without this I can guess: maybe check if you set a cookie expiration date? The following is an example of a cookie that is created after 1 day:

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

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

0
source
  • You can increase the expiration time of your Cookies (inside the code in which you create cookies).

  • You can use localStorage in your code instead of Cookies to save the value.

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

0
source

Source: https://habr.com/ru/post/1273896/


All Articles