ASP.NET - Log User Session Start/End Times for Audit Trail - Global.ASAX? -
P> 1) Windows ID - 2) session Start time - 3) session closing time - 4) being browsed URL (optional)
at the time of introducing some basic sessions have (See below) to log the code. Set the code in the global "session_start" method of ASACX, but it's still up to date. I am feeling that this is an ancient approach and there are "better" ways of doing this so I actually have two questions:
1) Is this the right way to go about doing this? If not, what are some other options?
2) If this is the right way, do I need to leave some code in the "session_and" method, when they record while exiting, and get a complete solution? Is this method always called when they close the browser tab on which to open the site, or close the whole browser (I do not have logout functionality)? Can anybody leave users on the end method of this session (or start up for that matter)?
as dim connsql new System.Data.SqlClient.SqlConnection (ConfigurationManager.ConnectionStrings ( "MyConnectionstring"). ConnectionString) Dim cmdsql as System.Data.SqlClient.SqlCommand = connsql.CreateCommand cmdsql .CommandText = "StartUserSession" cmdsql.CommandType = Data.CommandType.StoredProcedure cmdsql.Parameters.Add ( "@ windowsid", System.Data.SqlDbType.VarChar, 30, "Vindoaid") cmdsql.Parameters ( "@ windowsid") values = Session ("User Information"). Identity.name if connsql.State & lt; & Gt; System.Data.ConnectionState.Open then connsql.Open () cmdsql.ExecuteNonQuery () at the end as connsql.Close () Catch ex Exceptions ConnsqlkState & Lt; & Gt; Data.ConnectionState.Closed then try connsql.Close () end 'after the stored Proc record time start
Session_End is not trusted.
Do you suggest that you make a record that the session was created at that time, and in Session_End, the update is on session_start with the time it was finished.
To use the application_BeginRequest to handle the majority of sessions are passive derelict, to note when the user was "last time" to update the record
You will then need to determine a method of noting Sessions that are left inactive This site / app will be special. It may be as easy as selecting several minutes which should be considered leaving the session - like 10 minutes.
Then you have a query:
SELECT username, SessionStart, SessionEnd, LastSeenOn, DateDiff (miles, SessionStart, IsNull (SessionEnd, LastSeenOn)) from SessionAudit DurationMinutes Where SessionEnd Faucet or DateDiff (miles, LastSeenOn, getdate ()) & gt; 10
Your session will bring back the audit log.
Comments
Post a Comment