Limitting Number of Logged in Users or Active Sessions in ASP.NET

G

Guest

Hello,

This requirement might seem strange to someone out there, but here it's

We need to make sure only certain number of users can be logged in the site
at the same time. Is there any way to do that in ASP.NET, in web config file
or otherwise. Thanks in advance for your help.
 
S

Scott Allen

It's a difficult task. You could increment a counter when someone
successfully logs in, but they might never log off - they might just
close the browser. In these cases the best you can do is assume a user
has logged off after a period of time (say 5,10,20 minutes) when you
have not seen a request from them. Still - it might prevent other
users from getting in even though someone else has left the site.
 
G

Guest

Hi Lenn,

You can take a look to the Session_OnStart and Session_OnEnd of the
global.asax. The problem is that you can count all the started sessions, but
is very difficult to tell which of them are active. In order to have a better
idea of this, you can also hook to the BeginRequest event and check when the
last request of a given section happened. Within this you can get an
aproximate measure of the amount of users using your site (you can know
exactly the number of sessions started, but some of them may be abandoned or
inactive, waiting for its timeout, e.g the client closed the browser).

Anyway, is very difficult to be deterministic about this issue, specially
because the inherent statefullness of http, but with this techinques you can
get an approximate value (with an error margin). Another sugestion would be
to make some calculations and have a "safe-guard" number of sessions, which
will allow you to deal with the unused but active sessions.

Here you can find some info about global.asax...

http://msdn.microsoft.com/library/d...en-us/cpguide/html/cpcontheglobalasaxfile.asp

http://samples.gotdotnet.com/quickstart/aspplus/doc/globalasax.aspx

Regards,
Leon
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top