How could I get access to the Audit log for non-admin users?
I'm building a Web Part for SharePoint 2010 and I've found out that non-ad开发者_Python百科min users are getting Access Denied
error message when I execute the following code (the error is thrown in the last line):
SPAuditQuery wssQuery = new SPAuditQuery(web.Site);
wssQuery.RestrictToUser(web.CurrentUser.ID);
wssQuery.AddEventRestriction(SPAuditEventType.View);
wssQuery.RestrictToList(SPContext.Current.List);
SPAuditEntryCollection auditCol;
auditCol = web.Site.Audit.GetEntries(wssQuery);
How can I let non-admin users access this log from the web part? Because I need to filter by nono-admin users, even if a non-admin user is logged in at that moment.
.NET Reflector tells me that the SPAuditEntryCollection GetEntries(SPAuditQuery query)
method performs the following check before it attempt to retrieve data:
if (!this.m_Web.CurrentUser.IsSiteAdmin)
{
throw new UnauthorizedAccessException();
}
You can consider:
querying the
dbo.AuditData
table directly (accessing SharePoint database directly is generally discouraged, but you'll read-only access, so it shouldn't cause any problems),creating a custom SharePoint Web service - this should be simple, because all it needs to do is execute the
GetEntries
method and return the result.
精彩评论