p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   Sessions dont work (http://p2p.wrox.com/showthread.php?t=56581)

melkin April 12th, 2007 09:04 AM

Sessions dont work
 
Hi. I am a beginner here...

I want to simply have a session on a page for 30 minutes. After 30 minutes is up, to redirect to another .asp page.

Here is what I have:

<%Session.Timeout=30
if (Session.Timeout=0)then
%>
<%
Response.Redirect("cart_endsession.asp")
End If
%>

currently, it doesnt do a thing. Why?


planoie April 12th, 2007 09:24 AM

The TimeOut property of the session class "gets or sets the time the session is alive for". Not what the current time left is of a session. You need to solve this with javascript. Use the setTimeout js method and set the location.href property of the document.

-Peter

dparsons April 12th, 2007 09:31 AM

This is something that is continually asked on the forums; the short answer is that you can't. Instead of rehasing this again, read this thread:

http://p2p.wrox.com/topic.asp?TOPIC_ID=58564

It is in the 2.0 forum, but the same prinipal applies to you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========

melkin April 12th, 2007 10:08 AM

Ok, then how do I set the timeout on page one, and if a user goes to page two, page 2 timesout and redirects? can i do that with .asp timeout function?


dparsons April 12th, 2007 10:22 AM

Ok. Here is your crash course in Session State.

For my example I will use your example of a session that lasts 30mins.

When I first enter a web application my session begins and the clock starts counting down. Now if I make another request to the application *that has to go to the server for processing (another asp page)* my session timeout will be reset again to 30mins.

Now, If i stay on one page and do nothing for 35 mins and then try to request a page that needs session variables or something of that sort, they will not be available as my session has timed out and the session object destoryed. As Peter suggested, using Javascript is the most effecient way to detect when X amount of time has elapsed on a particular page.

All you need to do is:

setTimeout(location.href='timeout.asp', 3000000)

After 30 mins has elapsed, the javascript location.href will be called and it will send your user to another page letting them know that their session has timed out.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========

melkin April 12th, 2007 01:01 PM

Here is what I need to do....

I want a session to start as soon as a user visits my products page that will give them 30 minutes to shop...
Then I need the "view cart" page to timeout after knowing the timer is more than 30 minutes, and redirect to a "you have been timed out" page.

Can this be done?


dparsons April 12th, 2007 01:17 PM

Using purely asp? No. As peter and I have both said, you need to run a form of timer client side to generate this type of behavior. SetTimeout is just the type of timer you could use as it will raise a redirect when 30mins has expired.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========


All times are GMT -4. The time now is 11:00 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.