asp / iis question
anyone know if its possible with built in server commands to get a list of all the people currently authenticated to IIS with windows integrated authentication. I can get it showing the current logged in user with Request.ServerVariables ("LOGON_USER") but I want to see everyone?
No, since HTML is a stateless protocol - the user is only 'logged in' for the amount of time that it takes to generate and deliver the requested resource, after that they disappear.
i dont allow guest access so they need to enter their domain username and password to access the site. they are authenticated with this the whole time they are on the site.
is there no way to read these from the server ?
That's not quite what I meant. During a request for a resource, eg a web page or an image, the browser opens a connection to the server, authenticates, gets the resource, and then closes the connection. Next resource, same process. In practice, modern browsers tend to re-use the same connection to make it faster, but the point is: in between requests, there is no persistent information for the user, which is why it is called a stateless protocol. Unless you happen to have a look at the very moment they are fetching a resource, you won't see them.
Perhaps inefficient but you could have them create a temp file like a lockfile which is valid for 5 minutes before being nuked so you could just read from that list.
Powdarrmonkey is right, there is no way of reading this information directly from the server.
To provide a list of users similar to the on on the left of the edugeek front page is quite a simple process with IIS.
If you are running ASP.NET, then you can create a Global.asax page at the root folder of your site.
First, setup an Application variable in this file, this will be an array of usernames:
Sub Application_Start(ByVal sender as Object, ByVal e as EventArgs)
Application("UserList") = ""
You then have 2 Sub routines, as below
Sub Session_Start(ByVal sender as Object, ByVal e as EventArgs)
Application("UserList") = Application("UserList") & <Username> & ","
Sub Session_End(ByVal sender as Object, ByVal e as EventArgs)
Application("UserList").Replace(<Username> & ",", "")
These routines run whenever a session is started or closed on IIS. The first adds the current username to a comma separated string, the second removes it.
The Application("Usernames") string is available to use in any of your webpages, again as a comma separated list. You could use the Split method to break this down to an array if you need to.
Sorry this is a bit crude and there may be a more refined way of doing this but this is just off the top of my head.
Thanks for the replies. Its just regular asp not .net.
Its not really important I was just wanting to see if there was an easy way to see how often the site was being used. I guess I can just check the server logs :)
How about a single table database, where upon connection / page request, a row is added - ID, Name (From "LOGON_USER"), DateTime (=Now()).
Then, on the page where you are trying to get the current users, try
Dim Now = Now()
Dim fiveMin = Now - 5 Minutes (Not sure on syntax for this)
"SELECT * FROM TableName WHERE DateTime < fiveMin"
Bit of a clunky solution, bit it would probably work. I'd also look at implementing a batch script or something to clear out the table at regular intervals, as it will grow fairly quickly.
Also, You'd then need to remove duplicate names on the current users page, as a user could view page index.asp at 11:00, and again at 11:01, therefore creating two entries.
Hope this helps
In standard ASP, you can use the file global.asa and run code based on session_start and session_end to track the start/end of a sesion. this code could (eg) write the name to a database table at session_start and then remove it at session_end.
What are you trying to do? there might be a better way of achieving it.
I was hoping to just to be able to view who was accessing the site at any given time
This is the code that you are after I think:
ASP 101 - Articles
Thanks, thats pretty neat:
So is it impossible for me to tell what AD username is being used for each?
Session Id IP Address User Agent Session Start Time
696087857 127.0.0.1 Mozilla/5.0 ... 02/10/2008 21:34:49
Actually, I have added in a field in the global.asa and the test_page.asp to include the "LOGON_USER" server field.
Works great here on the laptop. Will test it out tomorrow :)
Session Id IP Address User Agent Username Session Start Time
696087858 127.0.0.1 Mozilla/5.0 ... VGNTZ\robert 02/10/2008 21:44:11
Worked last night on XP Pro IIS.
Originally Posted by RabbieBurns
Doesnt seem to work with 2003 IIS :(
got it working. I didnt use a big enough field and thats what the problem was :)
Originally Posted by RabbieBurns
Thanks SYNACK works like a charm