|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am designing an application that asks for a username (logon) on the first page and writes this onto the user's hard drive as a cookie. Then several asp pages later picks up the cookie and writes it into a database along with lots of other data that has been collected. It all works fine except when I use more than one pop-up window, then I lose the username. I even tried setting the expiration date of the cookie way in advance and I tried a session variable, but it still lost the username. I cannot figure out why.... can anyone help?
|
|
#2
|
||||
|
||||
|
Glad you're not tossing your cookies, at least.
![]() You might want to post a little code so some of the ASP weenies can take a look and diagnose the problem more readily. |
|
#3
|
||||
|
||||
|
Yeah - you shouldn't be losing session vars - no matter where you use them... except of course in a different domain. Ditto w/ cookies. You can't use cookies/session var across domains.
|
|
#4
|
|||
|
|||
|
On the login page I have this code to write the cookie...
Response.Cookies("UserName") = MM_valUserName Then on the main data entry page I have several buttons that open pop-up windows opening different asp pages for the user to enter stuff. The user may open all these pop-ups or none. If none or one are opened and entered, then the username cookie is still there, but enter two or more... Here is the code from the pop-up asp pages: Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <script language = "Javascript"> /** * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */ // Declaring valid date character, minimum year and maximum year var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i < s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strDay=dtStr.substring(0,pos1) var strMonth=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } day=parseInt(strDay) month=parseInt(strMonth) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ alert("The date format should be : dd/mm/yyyy") return false } if (strMonth.length<1 || month<1 || month>12){ alert("Please enter a valid month") return false } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ alert("Please enter a valid day") return false } if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){ alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear) return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ alert("Please enter a valid date") return false } return true } function ValidateForm(){ var dt=document.FormT7.Date_T7_1 if (isDate(dt.value)==false){ dt.focus() return false } return true } function confirmSubmission(){ if (confirm("Are you sure you want to submit this information?")){ return true; } else{ return false; } } </script> <% Response.Cookies("T7")=request("T7") Dim varT7 varT7 = request("T7") %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- InstanceBegin template="/Templates/Intranet.dwt.asp" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="doctitle" --> <title>T7 Data Entry</title> <!-- InstanceEndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="head" --> <link href="http://10.0.0.60/intranet/Text.css" rel="stylesheet" type="text/css"> <!-- InstanceEndEditable --> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px; } --> </style></head> <body> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td background="/Images/bg_top.gif"><img src="/Images/top_left2.jpg" width="179" height="72"></td> <td background="/Images/bg_top.gif"><div align="center"><img src="http://10.0.0.60/intranet/Images/top_logo.gif" width="340" height="72"></div></td> <td background="/Images/bg_top.gif"><div align="right"><img src="/Images/top_right2.jpg" width="179" height="72"></div></td> </tr> <tr> <td colspan="3"><table width="100%" border="0"> <tr bgcolor="#FFFFFF"> <td width="25%" valign="top"><!-- InstanceBeginEditable name="Menu" --><!-- InstanceEndEditable --></td> <td width="75%"><!-- InstanceBeginEditable name="Main" --> <% If Request("submitT7") <> "Close and Save" then %> <p> </p> <form action="T7.asp" method="post" name="FormT7" onSubmit="return ValidateForm()"> <table width="100%" border="0"> <tr> <td colspan="4"> <h5> Total number of responses not within 2 hours for metro POD's = <% Response.Write varT7 %></h5> </td> </tr> <% x=1 For x=1 to varT7 Set OraSession = CreateObject("OracleInProcServer.XOraSession") Set OraDatabase = OraSession.OpenDatabase("KPI_10.0.0.1", _ "kpiuser/cindy", Cint(0)) Set OraDynaset = OraDatabase.DbCreateDynaset( _ "select * from T_Reasons where question='T7' order by Reason", cint(0)) fAttempt=Request.Cookies("T7Attempt_" & x) %> <tr> <td width="18%">Attempted Delivery :<br> <% Select Case fAttempt Case "Yes" %> <input name="T7Attempt_<% response.write x%>" type="radio" value="Yes" checked>Yes <input name="T7Attempt_<% response.write x%>" type="radio" value="No">No <% Case "No" %> <input name="T7Attempt_<% response.write x%>" type="radio" value="Yes">Yes <input name="T7Attempt_<% response.write x%>" type="radio" value="No" checked>No <% Case Else %> <input name="T7Attempt_<% response.write x%>" type="radio" value="Yes" unchecked>Yes <input name="T7Attempt_<% response.write x%>" type="radio" value="No" unchecked>No <% end select %></td> <td width="18%">Reason :<br> <select name="Reason_T7_<% response.write x %>"> <option ><% If Request.Cookies("Reason_T7_" & x)<>"" Then Response.write Request.Cookies("Reason_T7_" & x) Else Response.write "Select Reason" end if %></option><% Do While(OraDynaset.EOF = FALSE) %><option value="<% = OraDynaset.Fields("Reason") %>"><% = OraDynaset.Fields("Reason") %></option> <% OraDynaset.MoveNext Loop %> </select></td> <td width="14%">Date (dd/mm/yyyy): <% If Request.Cookies("Date_T7_" & x)<>"" Then %> <input name="Date_T7_<% response.write x%>" type="text" value="<%Response.write Request.Cookies("Date_T7_" & x)%>"> <% else %> <input name="Date_T7_<% response.write x%>" type="text"> <% end if %> </td> <td width="14%">Run Number : <% If Request.Cookies("Run_T7_" & x)<>"" Then %> <input name="Run_T7_<% response.write x%>" type="text" value="<%Response.write Request.Cookies("Run_T7_" & x)%>"> <% else %> <input type="text" name="Run_T7_<% response.write x%>"></td> <% end if %> <td width="36%"> </td> </tr> <tr> <td colspan="4" valign="middle"><div align="left"> <p>Other comments:<br> <% If Request.Cookies("Comments_T7_" & x)<>"" Then %> <textarea name="Comments_T7_<% response.write x%>" cols="50" rows="2"><%Response.write Request.Cookies("Comments_T7_" & x)%></textarea> <% else %> <textarea name="Comments_T7_<% response.write x%>" cols="50" rows="2"></textarea> <% end if %> </p> <hr> </div></td> </tr> <tr> <td> </td> <td colspan="3"> </td> </tr> <% Next %> <tr> <td><input name="SubmitT7" type="submit" value="Close and Save" onclick="return confirm('Are you sure you want to submit information?')"> </td> <td> </td> <td colspan="2"> </td> </tr> </table> </form><input name="DiscardT7" type="submit" value="Close without saving" onclick="window.close()"> <% else y=Request.Cookies("T7") x=1 For x=1 to y Response.Cookies("Reason_T7_" & x)=request("Reason_T7_" & x) Response.Cookies("Date_T7_" & x)=request("Date_T7_" & x) Response.Cookies("Run_T7_" & x)=request("Run_T7_" & x) Response.Cookies("T7Attempt_" & x)=request("T7Attempt_" & x) Response.Cookies("Comments_T7_" & x)=request("Comments_T7_" & x) next %> <SCRIPT LANGUAGE="JavaScript"> function closeWin(){ window.close() } function timer(){ timerID = setTimeout("closeWin()", 1000) } </SCRIPT> Window will close in 1 second <script> timer(); </script> <% end if %> <!-- InstanceEndEditable --></td> </tr> </table></td> </tr> </table> </body> <!-- InstanceEnd --></html> Last edited by stumpy : February 1st, 2004 at 10:33 PM. Reason: Code not in code tags |
|
#5
|
|||
|
|||
|
how to fix it?
I think I know what is wrong but don't know how to fix it. On opening and closing windows, I am getting different session id numbers. How can I keep one session id throughout?
|
|
#6
|
||||
|
||||
|
You shouldn't be getting different session id, unless you completely close a session (close all the browsers which were running the session (i.e. your site)). If you change domains, and come back, that too might also start a new session. Basically, if you leave the site, your session will change. Otherwise, something else is doing it... i'd double check your code again, as you are using an awful lot of cookies. (Too many for my liking - too difficult to manage and track)
|
|
#7
|
|||
|
|||
|
What happends is from the main asp page I can open several other windows using buttons which open different asp pages. If I open say 2 of these windows, add data then close the windows it is fine, but if I open one of the same windows again to edit the data I already entered (hence the cookies) then it loses a previously entered cookie (even if I make it a persistent cookie) and I can see that it changes the session id.
Thanks in advance for any help guys. I am so stuck. |
|
#8
|
|||
|
|||
|
Cachine File size
I have whats sounds like the same problem. I found that increasing my temorary file cache size helped. I am still testing that but so far so good.
I had shut my temp file cache down to 64Meg on IE and 50 Megs on Mozilla. I have since increased both of them to 500megs and haven't had any trouble all mornging. Tim Quote:
|
|
#9
|
|||
|
|||
|
I just increased my cache, but it made no difference. I am going to try to redesign the site
![]() Thanks for the input. |
|
#10
|
|||
|
|||
|
Cache size
Yeah, I found later in the day that the problem was persisting. It did improve however.
our project is in Cold Fusion so we are switching to Client Variables that store in our MSSQL database. with ASP I have classically had to go with Session Vars instead of cookies. so instead of Request.Cookies just Session("mysessionvar") That's in VBScript. You will need to lookup the exact Syntax for JScript. I see that your example declared vbscript as the main page language and then Jscript int the Script tag. Session also likes to run server side. |
|
#11
|
|||
|
|||
|
I have started redesigning by putting all the variables on one page and using session("") and request("") - it works. Pity because now I have one extremely long page with lots if "If... else... end if" and code that is more difficult to debug. Takes a bit longer to load too.
Don't know if this will help you but I found this on MS site... might be worth a read... PRB: Session Variables Do Not Persist Between Requests After You Install Internet Explorer Security Patch MS01-055 http://support.microsoft.com/defaul...kb;en-us;316112 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Losing my cookies |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|