Cool. I will just add a Global.asax to my project and try adding my
code to the Session_Start procedure. I'll post the code here when I
get it finished.
I successfully added the Global.asax as a new item in my Visual Studio
2005 web project. I set some session variables and then store the
user, company and session id in an access database table called "Web
User Log". I was not successful in setting the session end time; it
just wasn't possible because my session state mode is not set to
InProc so I dismissed the idea. Here is the code if anyone is
interested....
Thanks to everyone for your help.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Session("IsDeveloper") = False
'Set session variables
If Not
IsNothing(Context.User.Identity.Name.Substring(Context.User.Identity.Name.LastIndexOf("\")
+ 1)) Then
Session("CurUser") =
Context.User.Identity.Name.Substring(Context.User.Identity.Name.LastIndexOf("\")
+ 1)
Dim CurDom As String = "DC=mydomain, DC=local"
Dim LdapSvr As String = "mydomain.local"
Dim LdapPath As String = "LDAP://" & LdapSvr & "/" &
CurDom & ""
Dim DirEnt As DirectoryEntry = New
DirectoryEntry(LdapPath)
Dim ds As DirectorySearcher = New
DirectorySearcher(DirEnt, "(sAMAccountName=" & Session("CurUser") &
")")
ds.PropertiesToLoad.Add("mail")
ds.PropertiesToLoad.Add("sn")
ds.PropertiesToLoad.Add("givenName")
ds.PropertiesToLoad.Add("company")
ds.PropertiesToLoad.Add("st")
ds.PropertiesToLoad.Add("l")
ds.PropertiesToLoad.Add("department")
Dim sr As SearchResult = ds.FindOne
Session("SN") =
sr.GetDirectoryEntry().Properties("sn").Value
Session("GivenName") =
sr.GetDirectoryEntry().Properties("givenName").Value
Session("mail") =
sr.GetDirectoryEntry().Properties("mail").Value
Session("Company") =
sr.GetDirectoryEntry().Properties("company").Value
Session("St") =
sr.GetDirectoryEntry().Properties("st").Value
Session("city") =
sr.GetDirectoryEntry().Properties("l").Value
Session("department") =
sr.GetDirectoryEntry().Properties("department").Value
End If
If UCase(Session("CurUser")) = "DEVDUDE1" Or
UCase(Session("CurUser")) = "DEVDUDE2" Then
'don't store login date/time for the web developers who
repeatedly log in and out while debugging.
Session("IsDeveloper") = True
Else
If Not Session("CurUser") Is Nothing Then
'now writing user name and login time to the WebBMQ
database Web User Log table upon new session
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.
4.0;Data Source=\myserver\webbmq.mdb;"
Dim conWebOrdNum As New
System.Data.OleDb.OleDbConnection(strConn)
Dim strIns As String = "INSERT INTO [Web User Log]
([User],[Company],[Date/Time of Entry], [Session ID]) VALUES
(?,?,?,?)"
Dim cmdIns As New
System.Data.OleDb.OleDbCommand(strIns, conWebOrdNum)
conWebOrdNum.Open()
If Session("CurUser") Is Nothing Then
Else
cmdIns.Parameters.AddWithValue("User",
Session("CurUser").ToString)
End If
If Session("Company") Is Nothing Then
Else
cmdIns.Parameters.AddWithValue("Company",
Session("Company").ToString)
End If
If Session("CurUser") Is Nothing And
Session("Company") Is Nothing Then
Else
cmdIns.Parameters.AddWithValue("Date/Time of
Entry", Now.ToString)
cmdIns.Parameters.AddWithValue("Session ID",
Session.SessionID.ToString)
End If
cmdIns.ExecuteNonQuery()
conWebOrdNum.Close()
End If
End If
End Sub