Users Counter

G

Guest

I want to control how many users there are login in my app

I have the following code on Session_Start

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();

and Session_End

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) - 1;
Application.UnLock();

I dont have a SignOut button on my App because users never press it, they
just go away or close the browser

the conclusion The sessions are not being closed, actually en Debug mode I
never see the Session_End Event came up.

Any idea or Link Where Can I Start?

ken
 
M

Marina

Are you waiting for the session timeout to be reached when you check the
count? Session_End only occurrs when the session is explicitly abandoned
(Session.Abandon) or when the idle timeout has been reached (as specified in
web.config). It does *not* happen when the browser is closed or when the
user navigates to a different page.
 
S

Steve C. Orr [MVP, MCSD]

By default a user's session ends 20 minutes after their last page request.
 
H

Hans Kesting

Kenny said:
I want to control how many users there are login in my app

I have the following code on Session_Start

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();

and Session_End

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) - 1;
Application.UnLock();

I dont have a SignOut button on my App because users never press it,
they just go away or close the browser

the conclusion The sessions are not being closed, actually en Debug
mode I never see the Session_End Event came up.

Any idea or Link Where Can I Start?

ken

Are you sure Application["NumVisitors"] always contains a count?
If it doesn't (first session!) then Application["NumVisitors"].ToString()
will crash. Solution: wrap it in a try/catch and set the value to 1
(in Session_Start) or 0 (in Session_End)

Hans Kesting
 
D

Do Quyet Tien

Why not code:

Application.Lock();
1 + (int)Application["NumVisitors"];
Application.UnLock();

instead of:

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();
 
G

Guest

using that code I got the message:

"Sólo se pueden utilizar las expresiones de objeto assignment, call,
increment, decrement y new como instrucción"


Do Quyet Tien said:
Why not code:

Application.Lock();
1 + (int)Application["NumVisitors"];
Application.UnLock();

instead of:

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();


Kenny M. said:
I want to control how many users there are login in my app

I have the following code on Session_Start

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();

and Session_End

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) - 1;
Application.UnLock();

I dont have a SignOut button on my App because users never press it, they
just go away or close the browser

the conclusion The sessions are not being closed, actually en Debug mode I
never see the Session_End Event came up.

Any idea or Link Where Can I Start?

ken
 
G

Guest

umm Ok I realize that what I want is not a User visitor Counter is a User
connected counter, because I need to now the real number or user actually
connected to the aplications, Is there a way to know it?

ken



Steve C. Orr said:
By default a user's session ends 20 minutes after their last page request.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Kenny M. said:
I want to control how many users there are login in my app

I have the following code on Session_Start

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();

and Session_End

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) - 1;
Application.UnLock();

I dont have a SignOut button on my App because users never press it, they
just go away or close the browser

the conclusion The sessions are not being closed, actually en Debug mode I
never see the Session_End Event came up.

Any idea or Link Where Can I Start?

ken
 
G

Guest

umm Ok I realize that what I want is not a User visitor Counter is a User
connected counter, because I need to now the real number or user actually
connected to the aplications, Is there a way to know it?

ken



Marina said:
Are you waiting for the session timeout to be reached when you check the
count? Session_End only occurrs when the session is explicitly abandoned
(Session.Abandon) or when the idle timeout has been reached (as specified in
web.config). It does *not* happen when the browser is closed or when the
user navigates to a different page.

Kenny M. said:
I want to control how many users there are login in my app

I have the following code on Session_Start

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) + 1;
Application.UnLock();

and Session_End

Application.Lock();
Application["NumVisitors"] =
int.Parse(Application["NumVisitors"].ToString()) - 1;
Application.UnLock();

I dont have a SignOut button on my App because users never press it, they
just go away or close the browser

the conclusion The sessions are not being closed, actually en Debug mode I
never see the Session_End Event came up.

Any idea or Link Where Can I Start?

ken
 
G

Guest

Hi Kenny,
I have same problem. After researching about the problem, I
discovered decision only for IE:((

Example:
in "<body .... " put - onunload="UnLoadWindows()"

<script language="JavaScript">
<!--
function UnLoadWindows()
{
var win_session;
var isIE = document.all;
if (isIE)
{
//IE
if (window.screenLeft < 10004)
{
//this is refresh
}
else
{
//this is close
//open new .aspx page, and delete all sessions
win_session=window.open
('frm_session_abandon.aspx','','width=1,height=1');
win_session.window.close();
}
}
else
{
//in case Mozilla !!! problems, because "onunload" event come and after
refreshing page, this is a problem, I don't found a verification (when is
refresh or close like IE)


}
}
//-->
</script>


If someone have another idea, please tell me :))

Ragards,
Stoyan
 

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

Top