PDA

View Full Version : Session Variables


rico1931
06-30-2008, 09:21 PM
Hi there folks,

I have a questions, I got my site in asp and using session variables to carry a username once logged in. I'm having the problem of session variables being carried over from one page to another. Anyone have any ideas why? I thought session variables carried from one page to another as long as it did not time out or close the browser. But here is the kicker if I hit the Refresh button the page shows up correctly and I can display the session variable but then when i move to another part of the site that shows the variable its gone again and I have to hit refresh, sometimes this works with one refresh hit or i have to keep doing it to display it.

How do I correct this problem?
-Thanks

davidj
07-01-2008, 06:55 AM
im not an ASP'er but this might help

http://classicasp.aspfaq.com/general/why-won-t-my-session-variables-stick.html

davidj
07-01-2008, 06:57 AM
or migrate to PHP and you wont have this problem

rico1931
07-01-2008, 01:54 PM
or migrate to PHP and you wont have this problem

Trust me I wanted to do this all in PHP but my company I am interning for restricts me to either ASP or ASP.NET. They seem to be loyal to Microsoft and don't wish to stray from them because of "support" they can provide. HA that's all I gatta say but thanks Davidj I'll read up during my lunch break and see if I can't figure something out. Oh and here is something wierd as well, the session variables only work in firefox and not in IE, Opera, or Safari.

davidj
07-01-2008, 02:23 PM
is this a cookie issue

have you allowed cookies on the browsers that dont work

this is the only thing i can think of

what about security settings maybe

rico1931
07-01-2008, 02:47 PM
is this a cookie issue

have you allowed cookies on the browsers that dont work

this is the only thing i can think of

what about security settings maybe

I thought this too but I enabled cookies on the browsers and checked the security settings and they are all allowing cookies, I also went into the IIS manager under home directory/ configuration/options and enabled everything except for side by side assemblies. I also increased the timeout and nothing. I put in a response.write sessionID into all my web pages and each time a new page is clicked it changes the ID but when I hit refresh it goes back to its original number and works fine. I went through the site and read a little and thats what I got. So now I know something wrong, the hard part is trying to figure out how to fix it now haha. Do you think it could be a problem that I don't have a global.asa file? I would make one but I have no clue where to sart with that.

davidj
07-01-2008, 03:07 PM
not sure mate as its not something i have encountered

sessions should be browser independent so this is weird. Maybe your server is buggy (I'm guessing IIS) try and repair it.

Does the Dir have the correct permissions (Clutching at straws here)?

do you have more than one instance of the browser /s open under the same login. Maybe a conflict of sorts?

rico1931
07-01-2008, 05:14 PM
I know its soo strange but opera seems to hold the sessionID just fine while safari, mozilla, and IE seems to change them every time. I think I will just try to go around the problem and make a global.asp file with the function to hold the sessionID. Then pass the variable through my web pages so the sessionID stays the same when they first visti the site. Do you think this is the best approach? i.e do you think this will work lol. I am going to go and try to learn how to properly use the Session_OnStart function but any help on how to begin will be greatly appreciated! :-D

rico1931
07-01-2008, 06:04 PM
hey davidj I finally did some more debugging and found that the issue is located somewhere in my damn template. So I need to redo the whole template but I don't get it. I have nothing in the template to change session Variables. Or do I and I am just not seeing it. Can you or anyone else here tell me where im going wrong with it. I spent a lot of time and the company really likes this template I don't just want to throw it away but I've spent so much time on this and need to move forward. Any feedback or advice would be greatly appreciated.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>DMIC Final Template</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<style type="text/css">
<!--
body {
background-image: url(/%7Eimages/site/gradiant.gif);
background-repeat: repeat-x;
font-family: sans-serif;
font-size: 10px;
}
#Container {
width:815px;
height:auto;
z-index:1;
background-color: #ECEBE8;
margin: auto;
}
#Banner {
left:17px;
top:12px;
width:800px;
height:auto;
z-index:2;
}
#LogIn {
width:150px;
height:auto;
z-index:20;
float: right;
}
#BannerLogo {
border: 2px solid #ECEBE8;
}
#TopNav {
width:auto;
height:40px;
z-index:2;
}
#LeftNav {
left:19px;
top:125px;
width:100px;
height:200px;
z-index:2;
float: left;
}
#Content {
left:132px;
top:125px;
height:355px;
z-index:3;
margin: 1px;
}
-->
</style>

<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

<link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="Container">
<div id="Banner">



<div id="LogIn">
<!-- TemplateBeginEditable name="LogInEdit" -->
Log In information will be inserted here.
<!-- TemplateEndEditable --></div>

<div id="BannerLogo"> <img src="/~images/site/dmic_header.gif" alt="DMIC_Logo" width="600" height="90"/>
</div>
</div>

<div id="TopNav">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a href="/Default.asp">Home</a> </li>
<li><a href="#" class="MenuBarItemSubmenu">Products</a>
<ul>
<li><a href="#" class="MenuBarItemSubmenu">Fluid Control Valves</a>
<ul>
<li><a href="/~prods/F01/bv/Ball_Valves.asp">Ball Valves</a></li>
<li><a href="/~prods/F01/cv/Check_Valves.asp">Check Valves</a></li>
<li><a href="/~prods/F01/fc/Flow_Controls.asp">Flow Controls</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Filtration</a>
<ul>
<li><a href="/~prods/F02/so/SpinOn_Assembles.asp">Spin On Assembles</a></li>
<li><a href="/~prods/F02/so/SpingOn_Mix_Match.asp">Spin on Mix + Match</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Gauges &amp; Isolators</a>
<ul>
<li><a href="/~prods/F03/ga/Gauges.asp">Gauges</a></li>
<li><a href="/~prods/F03/gi/Single_Station_Isolators.asp">Single Station Isolators</a></li>
<li><a href="/~prods/F03/gi/Multi_Station_Isolators.asp">Multi station Isolators</a></li>
<li><a href="/~prods/F03/ga/Gauge_Valves.asp">Gauges Valves</a></li>
<li><a href="/~prods/F03/gi/Snubbers.asp">Snubbers</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">SAE Flanges</a>
<ul>
<li><a href="/~prods/F04/sf/Split_Flanges.asp">Split Flanges</a></li>
<li><a href="/~prods/F04/th/Threaded_Flanges.asp">Threaded Flanges</a></li>
<li><a href="/~prods/F04/th/Threaded_90_Elbows.asp">Threaded 90&deg; Elbows</a></li>
<li><a href="/~prods/F04/sw/Socket_Weld_Flanges.asp">Socket Weld Flanges</a></li>
<li><a href="/~prods/F04/sw/Socket_Weld_90_Elbows.asp">Socket Weld 90&deg; Elbows</a></li>
<li><a href="/~prods/F04/bw/Butt_Weld.asp">Butt Weld</a></li>
<li><a href="/~prods/F04/bl/Blank_Flanges.asp">Blank Flanges</a></li>
<li><a href="/~prods/F04/hw/Hardware.asp">Hardware</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Hydrawlic Accessories</a>
<ul>
<li><a href="/~prods/F05/fb/Filler_Breathers.asp">Filler Breathers</a></li>
<li><a href="/~prods/F05/lg/Level_Gauges.asp">Level Gauges</a></li>
<li><a href="/~prods/F05/lgm/Leve_Guage_Manifold.asp">Level Gauges Manifold</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Components</a>
<ul>
<li><a href="/~prods/F06/gp/Gear_Pumps.asp">Gear Pumps</a></li>
<li><a href="/~prods/F06/pp/10,000_PSI_Piston_Pumps.asp">10,000 PSI Piston Pumps</a></li>
<li><a href="/~prods/F06/fd/Flow_Dividers.asp">Flow Dividers</a></li>
<li><a href="/~prods/F06/hydac/Hydrawlic_Actuators.asp">Hydrawlic Actuators</a></li>
</ul>
</li>
<li><a href="#" class="MenuBarItemSubmenu">Power Unit Layout</a>
<ul>
<li><a href="/~prods/F07/intro/Introduction.asp">Introduction</a></li>
<li><a href="/~prods/F07/sw-th/Socket_Weld_to_Thread.asp">Socket Weld to Thread</a></li>
<li><a href="/~prods/F07/hb-th/Hose_Barb_to_Thread.asp">Hose Barb to Thread</a></li>
<li><a href="/~prods/F07/hbspec/Hose_Barb_Specialties.asp">Hose Barb Specialties</a></li>
<li><a href="/~prods/F07/saeflagadapt/SAE_Split_Flange_Adapters.asp">SAE Split Flange Adapters</a></li>
<li><a href="/~prods/F07/4fcomp/4-Bolt_Companion.asp">SAE 4-Bolt Companion</a></li>
<li><a href="/~prods/F07/4fstd/4-Bolt_Standard.asp">SAE 4-Bolt Standard</a></li>
<li><a href="/~prods/F07/rtools/Reservoir_Layout_tools.asp">Reservoir Layout Tools</a></li>
<li><a href="/~prods/F07/bval/Bval_low_pressure_Ball_Valves.asp">BVAL Low Pressure Ball Valves</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Technical</a> </li>
<li><a href="#">News</a></li>
<li><a href="/Admin_Testing.asp" class="MenuBarItemSubmenu">Admin Testing</a>
<ul>
<li><a href="/Admin_Testing_Page/User_Page.asp">Current User Page</a></li>
<li><a href="/Admin_Testing_Page/Update_User.asp">Update Information</a></li>
<li><a href="/Admin_Testing_Page/Upload.asp">Upload Test</a></li>
</ul>
</li>
</ul>
</div>

<div id="LeftNav">
<!-- TemplateBeginEditable name="LefNavEdit" -->
Left nave will be place here
<!-- TemplateEndEditable -->
</div>

<div id="Content">
<!-- TemplateBeginEditable name="MainContent" -->
All content will be place here
<!-- TemplateEndEditable -->
</div>

</div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"/SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</html>

davidj
07-01-2008, 06:29 PM
i dont know myself

is this valid as part of your links...

"/~prods

rico1931
07-01-2008, 06:46 PM
Hi davidj

I found what was messing up the session variables! it was in the body css (crazy I know)
Check out body {
background-image: url(/%7Eimages/site/gradiant.gif);
background-repeat: repeat-x;
font-family: sans-serif;
font-size: 10px;

It was passing the image thru the url which I guess was changing the sessionID. WOW thats all I can say I didn't know that it would have that much of an impact on my site. Once I took that out the whole thing worked perfectly and the sessionID stayed the same throughout all web pages. haha now here is the kicker... know of any way on how I can put the image back in the background without passing it through the url? haha thanks davidj you've helped me out so much! You taught me to keep looking at it and I really appreciate you helping me througout this whole process!!! I owe you BIG TIME!!!!! :grin::-D

rico1931
07-01-2008, 07:04 PM
I still think you were right in there somewhere about ~prod because everytime I go to the new link under my folder ~prod the session changes but i'll figure it out thanks I may just start the template from scratch and test sessions as I go along. How do you close a thread? or mark it answered?

davidj
07-01-2008, 07:54 PM
im betting that %7E in this line...

background-image: url(/%7Eimages/site/gradiant.gif);

is hex for ~

remove all instances of ~

rico1931
07-01-2008, 08:32 PM
im betting that %7E in this line...

background-image: url(/%7Eimages/site/gradiant.gif);

is hex for ~

remove all instances of ~

Thanks davidj and thats exactly what I did. I made my website again back to the basics and i'm still coming up with the same problem check it out
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>DMIC-006 Template</title>


<style type="text/css">
<!--
body {
background-image: none;
background-repeat: repeat-x;
font-family: sans-serif;
font-size: 10px;
}
#Container {
width:815px;
height:auto;
z-index:1;
background-color: #ECEBE8;
margin: auto;
}
#Banner {
left:17px;
top:12px;
width:800px;
height:auto;
z-index:2;
}
#LogIn {
width:150px;
height:auto;
z-index:20;
float: right;
}
#BannerLogo {
border: 2px solid #ECEBE8;
}
#TopNav {
width:auto;
height:40px;
z-index:2;
}
#LeftNav {
left:19px;
top:125px;
width:100px;
height:200px;
z-index:2;
float: left;
}
#Content {
left:132px;
top:125px;
height:355px;
z-index:3;
margin: 1px;
}
-->
</style>

</head>

<body>
<div id="Container">
<div id="Banner">



<div id="LogIn">
Log In information will be inserted here.</div>

<div id="BannerLogo"> <img src="/images/site/dmic_header.gif" alt="DMIC_Logo" width="600" height="90"/> </div>
</div>

<div id="TopNav"> </div>

<div id="LeftNav">
Left nave will be place here </div>

<div id="Content">
All content will be place here<br />
This is the current sessionID:
<% Response.Write(Session.SessionID) %>
</div>
</div>

</body>
</html>


Its a basic site and holds the session variable for about 10-20 refreshes then it give you a new sessionID... is this normal? Does it suppose to give you a new sessionID after a certain amount of refreshes? I have nothing in my code to tell it so... oh boy what a day!

davidj
07-01-2008, 09:46 PM
try removing the first slash from all instances where you have this path structure

/images/site/dmic_header.gif

dont start a path with a slash

rico1931
07-01-2008, 10:00 PM
still the same.. I even went back and checked the IIS to make sure it was set up right and stopped and started it back up every time I load the new files on it. I'm starting to think maybe it has to do something with templates or dreamweaver making the templates. I made a test page with only "This is your SessionID" <% Response.write(Session.SessionID) %> and I refreshed the hell out of it and it stayed the same after holding down F5 for like a min. If I do that to this current site I get 2 seperate SessionID and I have pretty much stripped my template to nothing but the logo and div boxs. i'm so lost now.

davidj
07-01-2008, 10:03 PM
im not savy enough with asp to help any further

sorry

rico1931
07-01-2008, 10:29 PM
thank you very much davidj I really appreciate your help without you I wouldn't have come this far. If something changes in the next couple of days when I fix this I'll post it up. Until then or until I have my next question davidj ;-) Thank you

rico1931
07-02-2008, 07:35 PM
So I found out that the problem is with the spry menu. I took it out and everything works fine and dandy. I am going to try to see if I can find out why this is happening. Maybe its something that DW code puts in? Or maybe its my template.. I'll update soon enough.

rico1931
07-02-2008, 09:47 PM
So I just thought to start from absolutely nothing and test session variables to find out where exactly it brakes and I found it!. The session variables begin to change once I added the .css page. I know I said Spry before but that can be null and void because I got the Spry Menu to work in a stand alone environment and it help session variables just fine.

The problem was I have a background image and for some reason it just doesn't like url(some/image/path) in the css. I have tried both attaching the css and then just placing the css in the same document and both times the session variables change. Go ahead and try it and if im prove please tell me what I am doing wrong!?!?!?!?!(p.s after hitting refresh 25times just a little test). This is driving me crazy! does anyone have any ideas why this is happening. Can someone please try it out and tell me that im just crazy and its something wrong with the IIS server so I can go complain to my boss and finally stop getting yelled at (yes I am an intern) haha thanks!

-X

davidj
07-03-2008, 06:44 AM
well least you figured it out

php doesnt have this issue!

rico1931
07-07-2008, 06:07 AM
Ya it sucks though because now here is what I have found is that I can't have more then one image linking to the login page site (ya only the login page) but then after all the other pages will hold the session variable just fine. So I come up with the round about way of just making the login page be an annoying pop up WEBpage Browser or be a second page people are redirected to with only the login form. but just in case I want to go the route of a new webpage pop up with a window screen size of only 200 x200 how would I pass the javascript or window.open container to the parent page and not continue in the child page. I will start a new thread about this because the login behavior is from dreamweaver and it ask me to just type in the redirect page in the behavior pop up. If anyone has any ideas about how to change the login code

' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("Email"))
If MM_valUsername <> "" Then
Dim MM_fldUserAuthorization
Dim MM_redirectLoginSuccess
Dim MM_redirectLoginFailed
Dim MM_loginSQL
Dim MM_rsUser
Dim MM_rsUser_cmd

MM_fldUserAuthorization = "AUTH_LEVEL"
MM_redirectLoginSuccess = "/SessionID2.asp"
MM_redirectLoginFailed = "/Default.asp"

MM_loginSQL = "SELECT AUTH_EMAIL, AUTH_PW"
If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
MM_loginSQL = MM_loginSQL & " FROM dbo.AUTH WHERE AUTH_EMAIL = ? AND AUTH_PW = ?"
Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
MM_rsUser_cmd.ActiveConnection = MM_DMICSQL_STRING
MM_rsUser_cmd.CommandText = MM_loginSQL
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 50, MM_valUsername) ' adVarChar
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 50, Request.Form("Password")) ' adVarChar
MM_rsUser_cmd.Prepared = true
Set MM_rsUser = MM_rsUser_cmd.Execute

If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization ).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And true Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>

Thanks for the help.. remember its through the login behavior in DWcs3

davidj
07-07-2008, 06:34 AM
ahh right

you shouldnt use them behaviors

its not very professional

rico1931
07-07-2008, 06:46 AM
ahh right

you shouldnt use them behaviors

its not very professional

ya I understand that. Its a pain in the a** though and after talking to my boss thats the suggestion he gave. I bet the real deal is just how I typed up my HTML and when the page is being read its just not reading it in the right order thats why its getting messed up but he wants results now ya know and I really just want to get this done for him now so I can get my internship credits and fix it for him nicer when school starts. I may know more then and ask one of my prof face to face so we can tackle the problem. But thanks davidj for the fast response. What you guys dont sleep over there!!?!?!?!

davidj
07-07-2008, 08:35 AM
but its not you writing the code its dreamweaver and when it goes tits up you wont know how to fix it.

i never assist those who use these wizards as i dont know how to

i am not an ASP guy anyway so i couldnt help much even if you chose to write the code yourself

amanda
09-15-2008, 12:38 PM
thank you very much .I really appreciate your help without you this was not possible.