Strange Cookie in IE

I have a code that saves the user id as a cookie. It works great in production, but moves the code in IIS7, updates the provider application behind my code and moves the application to the application in IIS7 instead of just launching the Default Web, it breaks this cookie function in IE.

Unfortunately, this is a classic ASP application, so I cannot find a good way to publish a working version. But here are the relevant parts.

Description:

  • when the user checks "remember me" and logs in, a temporary cookie is created
  • when the user authenticates, the temp cookie "advances" to a persistent one and the pace has expired.
  • when the user cancels “remember me”, both cookies must have expired

What seems to be happening (only in IE?) Is that there are 2 cookies, and unchecking only one of them.

Here is the relevant code. Hope this helps :)

In the login form:

var MHOLI = Get_Cookie("MHOLI"); //Check if cookie has a value if (MHOLI != null && MHOLI != "" && MHOLI != "null") { //Set login text $("#Login").val(MHOLI); //keep remember login checkbox checked $("#RemonlineID").attr('checked', true); $(document).ready(function() { setTimeout(function() { $("#Password").focus(); }, 200); }); } $(document).ready(function() { //test if cookies are enabled.. Set_Cookie('test', 'testvalue', '/', '', ''); //if cookies are disabled, disable the option to remember username if (!Get_Cookie('test')) { $('#RemonlineID').attr("disabled", true); } });​ 

If the Remember Me checkbox is changed:

 var loginForm = document.getElementById("loginForm"); if (!loginForm.RemonlineID.checked) { setCookie("MHOLI", null, null); setCookie("tmpMHOLI", null, null); }​ 

When the login form is sent, set the cookie 1 day, if "remember me" is marked:

 if (loginForm.RemonlineID.checked) { setCookie("tmpMHOLI", loginForm.Login.value, 1); } else { setCookie("tmpMHOLI", null, null); }​ 

Function setCookie. Yes, I see that expstring exists, but is never used :):

 function setCookie(name, value, days) { var expireDate = new Date() //set "expstring" to either future or past date, to set or delete cookie, respectively var expstring = (typeof days != "undefined") ? expireDate.setDate(expireDate.getDate() + parseInt(days)) : expireDate.setDate(expireDate.getDate() - 5) document.cookie = name + "=" + value + "; expires=" + expireDate.toGMTString(); }​ 

And then some VBScript as soon as the user puts it into the application. I think it creates a second cookie instead

 if Request.Cookies("tmpMHOLI") <> "" then Response.Cookies("MHOLI") = Request.Cookies("tmpMHOLI") Response.Cookies("MHOLI").Expires = Date() + 365 Response.Cookies("tmpMHOLI") = "" end if 

Is there anything else in the way IE7 / 8/9 handles cookies so it doesn't work? Is there something about IIS7.5 that creates a cookie that the client script cannot touch?

+6
source share
2 answers

I have finished refactoring my setCookie() function. I did not have the right to expire cookies because the date calculations were funky. The quirksmode createCookie() function worked correctly.

Also, I set the path in the cookie when I set it on the server side. Somehow the paths were different for the cookies set on the prelogin and post login pages. Thus, the client script was unable to override the server side cookie and vice versa. Explicitly set the path that has been fixed.

0
source

There seems to be weirdness with IE / IIS7 and underscores in domain names. Could this affect you?

0
source

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


All Articles