views:

23

answers:

1

Hi... I am having a web application built using ASP and Asp.Net.I want to restrict number of users accessing this website.There are ways available separately ASP and ASP.NEt but,not for combination of these two. MayI know if I could just use Application["somename"] in global.asax

One more thing is when a user leaves the application, which means the session times out, user logs out on his own, or closed the browser I want to make sure that the Application["somename"] gets reduced. How to track these cases?

A: 

You mentioned the user logging out, so I'll just assume that you're using the Membership provider (or some other authentication paradigm). If so, the Membership provider specifically has a GetNumberOfUsersOnline() method. You could check that method prior to displaying a login form, and if the number you desire has been exceeded, don't allow any new users to log in. Of course that method is more or less accurate outside of a 15 minute window, so if you need something extremely precise, you'll have to do some customization to minimize said window.

Alternatively, you could indeed use the global.asax file in conjunction with an application variable, though the tricky part is obviously when to consider a user logged out if they don't explicitly do so.

alex
@alex - I am using session.abandon to kill the session during logout. As you said I am worried about the tricky part of closing the browser. I don't know how I can keep track of that and reduce the count for that use in my Application["somename"] variable.Thanks for you answer though.
SARAVAN