This topic is locked

Audit Log

1/16/2007 6:59:22 PM
ASPRunner.NET General questions
R
rob author

Hello,

I see alot of posts for audit log, except in the .net area. What I'm doing is writing to another audit table with username, timestamp, and the table/record that was changed. I tried the session("UserID") but this does not work. I also would like to insert the table/record that was changed. Any suggestions?

thanks!

Eugene 1/17/2007

Open Events tab in ASPRunner.NET. Select Table Events->Edit page->After record updated.

Then click Add action and select Insert a record into another table.

Then modify the code to fit your needs.

Here is the sample code you can use (vb.net 1.1 example):
[codebox] Dim sSQLInsert As String = "insert into AuditTable (ip, name,time) values (@ip, @name, @dt)"

Dim cn As New OleDbConnection(func.GetConnectionStr())
Dim cmdInsert As OleDbCommand = new OleDbCommand(sSQLInsert, cn)

cmdInsert.CommandType = System.Data.CommandType.Text
cmdInsert.Parameters.Add("@ip", OleDbType.VarChar).Value = System.Web.HttpContext.Current.Request.UserHostAddress

cmdInsert.Parameters.Add("@name", OleDbType.VarChar).Value = System.Web.HttpContext.Current.Session("User").UserName

cmdInsert.Parameters.Add("@dt", OleDbType.DateTime).Value = DateTime.Now()
cn.Open()

cmdInsert.ExecuteNonQuery()

cn.Close()

[/codebox]
Put the same code to Add page->After page is added event.
You can also use "Before record updated" event to save record that was changed.