how to maintain two session

Posted by Abhi_patil under ASP.NET on 4/14/2009 | Views : 2753 | Status : [Member] | Replies : 3
suppose i loggedIn in web application, then it open with new session.
i have done database updates on session time out. i have given 20 min time out. also i have called session.abondon() on direclty close the browser. but direct close is not detecting in mozilla, but that's no probelm, although u closes browser in mozilla, your session will expire after 20 min.

but suppose if u logged in again before previous session's time out to occur, u will be logged in with new session.
and when prev. session expires then it will change update database.

then even if u loggen in then ur online status will be offline b'caz it has changed by prev. session




Responses

Posted by: Vuyiswamb on: 4/14/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Abhi_patil

I have never Experienced this Problem before, what i do is that if the user want to logout by Clicking the logout Button, i abondon the Session, and if the user want to Close the Page from the (x), i trap that using javascript, and just there i abondon the Session. So in Ado.net when you Update data it get Upadated Automatically it will will not wait until your session expires, So Am not sure what do you mean when you say

session expires then it will change update database.


In the World of Ado.NEt this does not exists, if it does , you must know there are poor design decisions made.

You must Always abondon your session when you go out or if the session expires, and if it expires and you did not update your Data, your Data will remain in the Catch and nothing will happen to it until the Garbage Collector comesa and collect it

Thank you for Posting at DotnetFunda

were looking forward for your reply

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi_patil on: 4/14/2009 [Member] Starter

Up
0
Down
let me explain,
when u login it will update ur status as online in db.
when u logout it will update db status as offline.

when u closes browser then using javascript i have made session abondon.
in session end the code is to updates db for status as offline.
this direct close is working with IE not for Mozilla.


there fore when mozilla user closes browser directly.
it will not update db status.but when time out occurs t will updated.

In this case suppose mozilla user closes directly.
then application is close but it's session will still running untill it's time out.

but before time out if u again login then applin. will open with new session.this session will going on.

but when prev. session time out occurs it updated ur db status as offline.
but ur online with new session.

hope now u will understnd.
thank u.



Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/14/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
hi Abhi_patil

That has been a problem for Clients with Mozilla, there are ways to work around that please try the Following ways

What you can do is use AJAX and call code in the code behind in the browsers onunload event by capturing it through JavaScript.

http://www.w3schools.com/ajax/ajax_browsers.asp
or this one

protected void Page_Load(object sender, EventArgs e)


{

Session.Abandon();

}



Global.asax

void Session_End(object sender, EventArgs e)

{

string path = @"c:\temp\AbTime.txt";

if (!File.Exists(path))

{

using (StreamWriter sw = File.CreateText(path))

{

sw.WriteLine("Session Abandon Test");

}

}

using (StreamWriter sw = File.AppendText(path))

{

sw.WriteLine(DateTime.Now);

}

}



CloseBrowser.aspx

<script language=javascript>

function window.onbeforeunload()

{

if(event.clientX>document.body.clientWidth&&event.clientY<0)

{

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.open("GET"," AbandonSession.aspx",false);

xmlhttp.send();

}

}

</script>


or

try using these two lines of code in Session_End() function in Global.aspx file


Session.Abandon();

Response.ExpiresAbsolute = DateTime.Now;


or

Hope this Helps

Thank you for posting at Dotnetfunda
[Administrator]

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response