f631bd259462d667f95879ed82e3901efb0d6fe5
FAQ/Questions/Auditing-When-Accessing-Reports.md
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +#Audit Report Access & Exports |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Question |
|
| 6 | + |
|
| 7 | +How can I set up auditing so that whenever a user accesses or exports report data, an audit is performed? |
|
| 8 | + |
|
| 9 | +##Answer |
|
| 10 | + |
|
| 11 | +One way of doing this is to use the PreExecuteReportSet in your global.asax file. Every time a user clicks on print or exports, it fires a query. You would need to write the custom code in the PreExecuteReportSet method utilizing the querystring which contains the report name and output. You could then pass that data to a table in your database including the username, time, etc. |
|
| 12 | + |
|
| 13 | +##C♯ FileSystemAdHocConfig Example |
|
| 14 | + |
|
| 15 | +```csharp |
|
| 16 | +public override void PreExecuteReportSet(ReportSet reportSet) { |
|
| 17 | + Guid g = Guid.NewGuid(); |
|
| 18 | + XElement audit = new XElement("Audit", |
|
| 19 | + new XElement("AuditID", g.ToString()), |
|
| 20 | + new XElement("Name", AdHocSettings.CurrentUserName), |
|
| 21 | + new XElement("ReportName", reportSet.ReportName), |
|
| 22 | + new XElement("DateAccessed", DateTime.Now.ToString())); |
|
| 23 | + if (!Directory.Exists("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-"))) { |
|
| 24 | + Directory.CreateDirectory("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-")); |
|
| 25 | + } |
|
| 26 | + File.WriteAllText("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\" + g.ToString() + ".log", audit.ToString(), Encoding.UTF8); |
|
| 27 | + base.PreExecuteReportSet(reportSet); |
|
| 28 | +} |
|
| 29 | +``` |
|
| 30 | + |
|
| 31 | +##VB.NET FileSystemAdHocConfig Example |
|
| 32 | + |
|
| 33 | +```visualbasic |
|
| 34 | +Public Overrides Sub PreExecuteReportSet(ByVal reportSet As ReportSet) |
|
| 35 | + Dim g As Guid = Guid.NewGuid() |
|
| 36 | + Dim audit As XElement = New XElement("Audit", _ |
|
| 37 | + New XElement("AuditID", g.ToString()), _ |
|
| 38 | + New XElement("Name", AdHocSettings.CurrentUserName), _ |
|
| 39 | + New XElement("ReportName", reportSet.ReportName), _ |
|
| 40 | + New XElement("DateAccessed", DateTime.Now.ToString())) |
|
| 41 | + If Not Directory.Exists("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-")) Then |
|
| 42 | + Directory.CreateDirectory("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-")) |
|
| 43 | + End If |
|
| 44 | + File.WriteAllText("C:\\Reports\\Audits\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\" + g.ToString() + ".log", audit.ToString(), Encoding.UTF8) |
|
| 45 | + MyBase.PreExecuteReportSet(reportSet) |
|
| 46 | +End Sub |
|
| 47 | +``` |
|
| 48 | + |
|
| 49 | +_**Note:** For this example, you will need to use a version of the .NET framework that uses ``System.Xml.Linq``_ |
|
| ... | ... | \ No newline at end of file |