How can we terminate a user's session

A

ad

In some condition, like another user log in with the some ID, I want to
close a user's session.
How can we terminate a user's session with program?
 
M

Mark Rae

In some condition, like another user log in with the some ID, I want to
close a user's session.
How can we terminate a user's session with program?

See my earlier reply about session timeout - basically, you can't...

Remember that IIS sessions are by definition independent of each other so,
unless you record each successful login in something like SQL Server, one
session can't have any knowledge about any other session.

However, if you do log each successful login, you could very simply add code
to the OnInit of each ASPX's code-behind which did something like:

if(<some condition fetched from SQL Server>)
{
Session.Abandon();
}
 
A

ad

Thanks for your immediately answer.
But I want close specific session, not the session right now.
My scenario:
I prepare a database table (name UserOnLine) to log the User ID and Session
ID of user.

When a use login with a ID (Say User1) I check the UserOnLine table, If
there no User1 in the UserOnLine table, run the common login process.
But if the User1 ID already in UserOnLine table:
1. Fetch the SessionID of User1 in UserOnLine table.
2. Abandon the Session of that SessionID
3. Process common login process.

My question is :
1. How to get the session ID when a user login?
2. How can we abandon a specific session?
 
M

Mark Rae

1. How to get the session ID when a user login?
HttpContext.Current.Session.SessionI

2. How can we abandon a specific session?

Don't even try - rethink your application design...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top