Click to See Complete Forum and Search --> : [RESOLVED] Session Conflict


toraj58
December 30th, 2008, 04:36 AM
i need to have seperate Session objects in my site;
becuase when i use Session.Abandon();

i don't want to destroy all of them.

for example i use a session to check the user that logged in admin area.

and another session to check user logged in members ares.

like this:


Session["loggedAdminArea"] = true;

//somewere else in the code...

Session["loggedMemberArea"] = true;

//somewere else in the code...

Session.Abandon();



but when i uses Session.Abandon(); both of them destroy.

in the cases when admin (in one system) both loggin in the admin area and loggin in the members area it causes a logg off in both after calling Abandon method.

how shoud i use Abondon method to destroy particular sessions or should i change my approach completely?

dannystommen
December 30th, 2008, 05:10 AM
So you mean that the admin logs in for both admin and member in the same browser(window), or a different one?

If he logs in in 2 different browser, the Session.Abondon should not be a problem, it's the same way I do and it works fine.

Asuming you mean with 'in one system' that the admin logs in twice in the same browser, for as far I know, this is not possible to have multipile sessions.
Instead of making 2 different log ins, you could make 1 with admin rights.

But propably you have this approach for a particular reason.

Another was to solve it maybe is the next approach:

private void LogOutAdmin() {
Session["loggedAdminArea"] = false;

bool memberLoggedIn = Convert.ToBoolean(Session["loggedMemberArea"]);

if (!memberLoggedIn) {
//both admin as member are logged out
Session.Abandon();
}
}

private void LogOutmember() {
Session["loggedMemberArea"] = false;

bool adminLoggedIn = Convert.ToBoolean(Session["loggedAdminArea"]);

if (!adminLoggedIn) {
//both admin as member are logged out
Session.Abandon();
}
}


Only Abondon the session when both uses are logged out

toraj58
December 30th, 2008, 05:51 AM
it is a special case in the situations when admin (who is not really a programmer and don't know about sessions) login in the admin area then for checking something login with the password of the member in a same browser and then logoff in the member area. then he notice that also logged off in the admin area.

i have thought about the same solution that you proposed but i don't want to retain unneccessary information in the server; maybe it is better to make those session objects that are not usefull anymore to null then let GC to collect them. is this better?

dannystommen
December 30th, 2008, 06:11 AM
Don't make it a session variable null but just remove it:


Session.Remove("loggedAdminArea")

toraj58
December 30th, 2008, 06:31 AM
yes; i did not care to Remove method. it is better....thanks.