Register  |  Login



Earn money by sharing your knowledge

Quomon shares its advertising revenue with contributing experts that answer questions effectively. Join our community to share your knowledge and earn an income as you go.

Question

Status: Closed Points: 100 Time: 01:57 - Jan 11, 2007  

david

checking that session ended in asp.net?

Hi,

I need to check if the session has ended in asp.net 2 and write a message accordingly to the user to do that.
Is there inbuilt functionality to do that, or will I have to implement something like leaving a cookie on the users machine to identify him as a recent visitor and then checking if the session is set or not?
Or any other options?

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

rcastagna

Date:: Jan 11, 2007

Time:: 10:04

David,

There's a couple ways you can handle this one.

.NET 2.0 makes it very easy if you have the person "log in" to the system. HttpContext.Current.User.IsAuthenticated with evaluate "true" if they have been authenticated and have not timed out. Once they timeout, they'll be taken to the login page before being able to proceed. Unfortunately, all info that may be associated with that session would probably be lost.

I've also done a cookie in the past where I set the SessionID (you can also put this in a session variable if you want) and then when they "come back" to the server, check to see if the Session.SessionID currently on the server matches what's stored in the Cookie/Session Variable. If it is, they're still "OK"...if not, I send them to a function that clears out what's been set and redirects them to the "start over" page.

This solution relies on the session timeout settings for the website, so if you want to handle it programmatically, you'll probably want to look at a client-side Javascript solution, which is how I accomplished the scenario below:

If you want to alert the visitor that their session is about to timeout, it's more difficult. I've put together a javascript timer using the javascript setTimeout() function that after x minutes/seconds/hours an alert is popped up warning them they're about to expire. If they reach the end of the timer period, I do a javascript redirect to the login page.

setTimeout is the Javascript function to research.

I hope this helps get you on track.

Ric

david

Date:: Jan 27, 2007

Time:: 07:23

Ric, thank you for the info about the IsAuthenticated boolean, I didn't know about that.
I have chosen the cookie way, but don't need to tell the user that the session is about to expire. So handling it on the server is fine.
And the points go to.... rcastagna.

Question Answered

This question has been closed, and points have been rewarded to the following experts:

rcastagna: 100

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top asp.net Experts

View More

Rank

Expert

Points

1.

rcastagna

738

2.

PeterNZ

495

3.

nidhi

450

4.

Anpanman

297

5.

multani.sarbjit

215

6.

dustPuppy

75

7.

joxley

50

8.

ozzie

50

9.

Zoush

50

10.

xarcus

30

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es