Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables

Status
Not open for further replies.

Silvinho

Programmer
Jul 9, 2001
58
0
0
GB
Ive got an ASP Script that collects an ID from a form and sets its as a Session Variable ie:

<%Session(&quot;ID&quot;) = request.form(&quot;MemberID&quot;)%>

this works fine but then at the end of the script there is a response.redirect to another page but the Session variable isn't passed to the rediret page.

Can anyone help?
 
so what you are saying, is that when you request the session variable, it is not thier.....


ie


<% =Session(&quot;ID&quot;) %>

or not
 
Why don't you do a response.redirect with a querystring..

ie.

<% Response.Redirect &quot;'mypage.asp?Parm1=&quot; & request.form(&quot;MemberID&quot;) &quot;'>

%>

Regards
Rob
 
Yes the Session Variable is not there when requsting it after redirecting.

I cant use the query string as another ID already uses it to get to the new page.
 
Silvinho,

The page you are redirecting to is on the same server? If so, assuming it worked on the one page like you said it did, I cannot think of a reason for it to not work correctly on the next page unless you abandoned the session or you have the session set to expire very soon after it is set.

E-Z-E
 
If you have the session disabled within IIS then you would not be able to carry it over to any other pages (I'd be surprised if you could use it at all).

Another reason it may not work is if the browser you are currently working with has it's security set to not allow per-session cookies, then it also will not work.

Or, as EZZEEE said, if the session timeout is to such a short amount of time that it times out before you are transfered to the next page, then it would have timed out and it would not exist anymore.
-Ovatvvon :-Q
 
Silvinho, what version of IIS are you on?

I have noticed that on my WIN2K box I can response.write a session variable to the screen. Then when I move to another page via a form action or redirect I do another response.write. The Session value is there. But if I do this on my NT4 box the session is lost!?!

I have sessions set to expire after 20 min, I also have sessions turned on for the entire web server. I also set my IE 5.5 & 6 borwsers to accept all cookies.

Shouldn't this work? What the heck is wrong?

Craig
 
Ctarr, NT 4.0 is just &quot;buggy&quot;...
I have to work with these at work and on what should work normally (and does on win2k) has problems on NT 4. Just moving from page to page while making DB connections on each has problems...sometimes it just stalls with a white page searching forever and never comes up to present data. If I close the browser, re-open it and try again it works fine (and yes my coding is done right :)).

Wish work would just upgrade to win2k...but that won't happen until they send it up the ladder and 2 years later it'll finally get approved (literately!).

Don't know what to tell you. If you're sure your code is right and your settings within IIS are correct, and you have SP6a installed, then all I can attribute it to is NT 4 itself. :-(
-Ovatvvon :-Q
 
Hi guys,

I use a similar approach as Silvinho in order to show certain pages only to logged-in people (administrators of a conference website). The application was tested under PWS/IIS 4.0 (=the version you can install on a NT4.0 Workstation) and is running on a &quot;proper&quot; NT4.0 Server since over a year without problems (well, without problems as being discussed here :)

In my application I have a login screen which asks for a password. When the password is OK, I set a session variable ILoggedIn to &quot;OK&quot; (Session(&quot;ILoggedIn&quot;) = &quot;OK&quot;)

On top of each protected page, I check if the session variable is still equal to &quot;OK&quot; - if so, I show the page, else I redirect to the login screen page.

I have my Session timeout set to the standard 20 minutes, and this works fine. Thus, I would think that the problem doesn't lie with NT specifically, but more with the particular configuration of the server (or a programming error)...

DrMaggie

---------
&quot;Those who don't know the mistakes of the past won't be able to enjoy it when they make them again in the future.&quot;
— Leonard McCoy, MD (in Diane Duane's Doctor's Orders)
 
Well, I have spent some time trying to figure out why my NT4 server is loosing my session. I have traced it down to the fact that my session Session(&quot;MyID&quot;) holds 9 values. All but 1 are strictly strings. The other is a string but does contain some digits. I belive the problem is when I pass the value to the session I wasn't explictly passing it as a string. So, it was going as a variant type and possibly by ref?? So when I went to another page that value of the session was gone. Actually, when I called that specific value from the session it was set to winnt/system32/asp.dll or some other string and file reference...That gave me a really bad feeling.

So, I went back through my code and made sure that the values were being passed as strings and by value and not by ref.

Craig :-0
 
I found this thread and though, here is my answer, but it seems there is no resolution. I also cannot access session variables from one page to the next. My session is enabled on IIS and the timeout is 20 minutes. I set the variable on one page and even put the value in the query string to make sure it is REALLY set (it is). Then I go to the next page and there is no value.
I know the reason is because I am getting a new session for every page or refresh. However, I don't know why I am getting a new session. Again, session is enabled in IIS (Win2K Server), timeout is 20 minutes, and cookies are enabled..... Anyone ever figure this one out?
 
Make sure cookies are enabled in your browser. Session Variables do place a small cookie on your client machine that holds the SessionId value so that it can reference the table of session variables and pull out your specific data. If your browser is not allowing the cookie, then each page IIS will attemnpt to give you a new session because it cannot detect one already on your system.
-Tarwn ------------ My Little Dictionary ---------
Extreme Programming - (1)Trying to code before my second cup of coffee. (2) While(1){ Ctrl+C; Ctrl+V; }
FAQ - Web-ese for &quot;Forget Asking Questions, I am to busy&quot; :p
 
Hi... I feel like I'm jumping in the deep end here.. but...
I'm updating code that my colleague has worked on. He's not here else I'd ask him...

Basically I can't get the ID to become a Session(&quot;ID&quot;) -when I go to the next page the ID is blank.

I've tried setting it in two places.. within the Trans and once its committed. It writes to the file fine.. but I can't understand why its not passing to the nect page.

I'm pretty sure it isn't to do with the browser as other pages set up the same way work!!

Thanks :)

conObj.BeginTrans
set cmdObj = Server.CreateObject(&quot;ADODB.Command&quot;)
set cmdObj.ActiveConnection = conObj
cmdObj.CommandText = &quot;INSERT INTO TableName (Value1, Value2) VALUES(?, ?)&quot;
cmdObj.Parameters.Append cmdObj.CreateParameter(&quot;Value1&quot;, adVarChar, adParamInput, 50, ScreenValue1)
cmdObj.Parameters.Append cmdObj.CreateParameter(&quot;Value2&quot;, adVarChar, adParamInput, 50, ScreenValue2)
cmdObj.execute
ID = conObj.Execute(&quot;SELECT @@Identity&quot;).Fields(0)

Session(&quot;ID&quot;) = ID

conObj.CommitTrans

Session(&quot;ID&quot;) = ID
Response.Redirect &quot;nextpage.asp&quot;
 
Let's start from zero, can you print the ID after

ID = conObj.Execute(&quot;SELECT @@Identity&quot;).Fields(0)
Response.Write &quot;ID:'&quot; & ID & &quot;'&quot;

If so, try to print the Sesion(&quot;ID&quot;) after set the ID
Session(&quot;ID&quot;) = ID
Response.Write &quot;Session ID:'&quot; & Session(&quot;ID&quot;) & &quot;'&quot;

If also work, then try do not use response.redirect but use javascript to go another page.

'Response.Redirect &quot;nextpage.asp&quot;
%>
Remove this link and close asp tag and add following code

<Script Language=&quot;JavaScript&quot;>
window.open (&quot;nextpage.asp&quot;, &quot;_self&quot;)
</Script>

Good luck!


Tony
 
nzgirl, what OS is the server running? As written above NT can and will act weird.

When you set the Session(&quot;ID&quot;) = ID Try setting it equal to &quot;&quot; + ID + &quot;&quot;. This will basically make the ID into a string and should save the value.

I've had problems where I set the ID and when I close the recordset I lose the value. But, when I force the value to be equal to a empty string plus the value plus an empty string it sticks.

Craig
 
Thanks for the response!!

My workmate is 'sick' today...

I can response.write after:
RecipientID = conObj.Execute(&quot;SELECT @@Identity&quot;).Fields(0)
and that has the correct values

And then the session stuff started working... (once I corrected my speeling mistake)

feeling a little sheepish but thanks for your help :)
 
I to am having this same problem with NT4.0. I developed my code on win2k and all has worked flawlessely. Once the code was moved over to our production server running NT4.0, weird things started happening. First, when I move from one page to another when using the netbios name of our server session state is not preserved. When I use the ip address instead of the netbios name, the application works as designed.

Here is a snippet of how Im defining my session values.


session(&quot;user_name&quot;) = request(&quot;user_name&quot;)
session(&quot;user_code&quot;) = RandomPw(10)
session(&quot;user_date&quot;) = request(&quot;user_month&quot;) & &quot;/&quot; & request(&quot;user_day&quot;) & &quot;/&quot; & request(&quot;user_year&quot;)
session(&quot;db_date&quot;) = request(&quot;user_year&quot;) & &quot;-&quot; & request(&quot;user_month&quot;) & &quot;-&quot; & request(&quot;user_day&quot;)
session(&quot;user_time&quot;) = request(&quot;user_hour&quot;) & &quot;:&quot; & request(&quot;user_minute&quot;) & &quot; &quot; & request(&quot;user_amorpm&quot;)
session(&quot;db_time&quot;) = FormatDateTime(session(&quot;user_time&quot;),4)
session(&quot;user_room&quot;) = request(&quot;user_room_id&quot;)
session(&quot;user_bed&quot;) = request(&quot;user_bed_id&quot;)
session(&quot;user_minutes&quot;) = request(&quot;user_minutes&quot;)


This page is a form if user_name is blank, and then if user_name isnt blank it moves down to this portion of code and displays the session info correctly. Once this second form is processed it goes to an action page that kicks off a sql insert statement. This is where the session values are not passing.

What is up with WINS that would cause this not to work?? Anyone have any ideas or can offer any help?

Thanks,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top