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?