iis7 is it possible to find out how long it has been since someone last accessed a website

Hi,

People are asking me to up my session time to 4 hours so they don't have to keep logging in and out. But, one of the issues for me is I like the flexibility of knowing there is no one on the site so I can make a quick change. And if I set the timeout to 40 mins I can see when all the sessions have ended because session_end is called in the site.

Is there any way to know how long it has been since someone accessed the website, so for instance if it has been an hour or two and it is 6pm in the evening, I can feel comfortable to make a change rather than having to send mails out to every etc etc.

thanks, Aiden
AidenAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sybeCommented:
For the same purpose I use an application variable which is an two-dimensional array. Each active user has its own element in that array with "user_id" and "last-active"

At each request of a user that array is updated.

When I want to know who is online and how long ago he was active, I loop through that array.
0
AidenAAuthor Commented:
can you clarify a bit? how do you do that?

where do you put it in your code? obviously there are lots of actions a user can take so you can't be updating an application variable in each button click for instance... or ajax call? Do you put it in page load then?

Could you provide a bit of your code maybe so I can get a better idea?
0
sybeCommented:
> where do you put it in your code?

In an include that is included on every page (in my case "header.asp" in which also for example the database connection is made)

> so you can't be updating an application variable in each button click for instance

I want to know the last activity, so on every request to the server the application variable is updated. If the user does something that does not require a request to the server (such as scrolling the page, writing in a form, but not submitting), then the application variable is not updated.


attached some sample code. Could probably be more efficient.


Sub UpdateApplicationArray()
	Dim iApplicationUser, aApplicationUserArray, aNewApplicationUserArray, iCounter

	If Not Session("_login") Then Exit Sub

	Session("_userinactive") = Timer
	aApplicationUserArray = Application("_users")
	iApplicationUser = CheckIntegerZero(Session("_applicationuser"))

	If Not IsArray(aApplicationUserArray) Then
		ReDim aApplicationUserArray(2,3)
		Application("_users") = aApplicationUserArray
	End If

	If iApplicationUser = 0	Then
		iApplicationUser = FindUserInApplicationArray
		If iApplicationUser = 0	Then iApplicationUser = FindLowestFreeUserInApplicationArray
		Session("_applicationuser") = iApplicationUser
		If iApplicationUser > Ubound(aApplicationUserArray) Then
			ReDim aNewApplicationUserArray(iApplicationUser,3)
			For iCounter = 0 To Ubound(aApplicationUserArray)
				aNewApplicationUserArray(iCounter,0) = aApplicationUserArray(iCounter,0)
				aNewApplicationUserArray(iCounter,1) = aApplicationUserArray(iCounter,1)
				aNewApplicationUserArray(iCounter,2) = aApplicationUserArray(iCounter,2)
				aNewApplicationUserArray(iCounter,3) = aApplicationUserArray(iCounter,3)
			Next
			aApplicationUserArray = aNewApplicationUserArray
			'Redim Preserve can only increase the last dimension...

		End If
		aApplicationUserArray(iApplicationUser,0) = True
		aApplicationUserArray(iApplicationUser,1) = Session("_userfullname")
		aApplicationUserArray(iApplicationUser,2) = Timer
		aApplicationUserArray(iApplicationUser,3) = Session("_id")
	Else
		aApplicationUserArray(iApplicationUser,2) = Timer
	End If
	Application("_users") = aApplicationUserArray

End Sub


Function FindLowestFreeUserInApplicationArray()
	Dim iCounter, aApplicationUserArray

	aApplicationUserArray = Application("_users")

	For iCounter = 1 To Ubound(aApplicationUserArray)
		If Not CheckBoolean(aApplicationUserArray(iCounter,0)) Then
			FindLowestFreeUserInApplicationArray = iCounter
			Exit Function
		End If
	Next
	FindLowestFreeUserInApplicationArray = Ubound(aApplicationUserArray) + 1
End Function


Function FindUserInApplicationArray()
	Dim iCounter, aApplicationUserArray

	FindUserInApplicationArray = 0
	aApplicationUserArray = Application("_users")
	If Not IsArray(aApplicationUserArray) Then
		ReDim aApplicationUserArray(2,3)
		Application("_users") = aApplicationUserArray
	End If
	For iCounter = 1 To Ubound(aApplicationUserArray)
		If CheckBoolean(aApplicationUserArray(iCounter,0)) AND Session("_id") = aApplicationUserArray(iCounter,3) Then
			FindUserInApplicationArray = iCounter
			Exit Function
		End If
	Next

End Function
=================================

' global.asa

Sub Session_OnEnd
	Dim aApplicationUserArray, iApplicationUser
	
	aApplicationUserArray = Application(Application("applicationname") & "_users")
	iApplicationUser = Cint("0" & Session(Application("applicationname") & "_applicationuser"))
	If iApplicationUser > 0 Then
		aApplicationUserArray(iApplicationUser,1) = False
		Application(Application("applicationname") & "_users") = aApplicationUserArray
	End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

AidenAAuthor Commented:
well i was just thinking... an easy way to do it would be just to check the log files? For instance... it's 12.17 now (where I am)... if I check the log file I can see that the last action was

2011-12-16 12:02:55 xx.xxx.xx.xxx POST /ManualTasks/User.aspx - 80 frstname.surname xx.xxx.xx.xx Mozilla/4.0+

I'm not sure why... but I can see the firstname.surname of the person also. Although I can't think where exactly that's coming from.

So, I guess that solves the issue really? Although thanks for the code I'll keep in mind in case there's something wrong with that method. What do you think?
0
sybeCommented:
Are you sure that each log entree is written immediately? Because I've seen machines where the logs are kept in memory until at some point a batch was written.

I still think it is nice to know who is "online" and see that easily in the browser. Suit yourself however.
0
AidenAAuthor Commented:
yeah, i'm not sure, but it seems pretty immediate from what I can see. I'll just do it that way for the moment but may well implement your code at some stage if it looks like it's not working properly

thanks, Aiden
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.