Apr 30 2020 10:01 AM - edited Apr 30 2020 10:05 AM
Hi there,
my logic is when we auto-create a personal site and add a record into backend custom list. meantime the event handler will be triggered to config audit log and site policy in each personal site.
but sometimes I ran into a problem is like the following situation. does anyone have any idea on it??
Thanks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[12:53 AM] [ERROR] litwareinc\vladime Additions to this Web site have been blocked.
Please contact the administrator to resolve this problem.
[12:53 AM] [ERROR] at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.SetWebMetainfo(String bstrUrl, WebPropertyBagUpdateFlags flags, Object varMetainfo)
at Microsoft.SharePoint.SPWeb.UpdateProperties(StringDictionary data)
at Microsoft.SharePoint.SPSite.set_AuditLogTrimmingRetention(Int32 value)
at OGCIO.ER.UPS.ActiveFeatures.DoWork.<>c__DisplayClass4_0.<ActiveAuditLogs>b__0()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at OGCIO.ER.UPS.ActiveFeatures.DoWork.ActiveAuditLogs(SPItemEventProperties properties)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
my code:
private static void ActiveAuditLogs(SPItemEventProperties properties)
{
try
{
Logging.WriteInformation(" Entering function ActiveAuditLogs");
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
SPFieldUrlValue sPFieldUrlValue = new SPFieldUrlValue(properties.ListItem["sp_Personal_Site_Location"].ToString().Trim());
Logging.WriteInformation(" Connecting to personal site " + sPFieldUrlValue.Url);
using (SPSite sPSite = new SPSite(sPFieldUrlValue.Url))
{
sPSite.TrimAuditLog = true;
sPSite.AuditLogTrimmingRetention = 30;
sPSite.Audit.AuditFlags = SPAuditMaskType.All;
sPSite.Audit.Update();
Logging.WriteInformation(" Updated to Auditlog Settings");
}
properties.ListItem["sp_Auditlog_Enabled"] = 1;
properties.ListItem.SystemUpdate();
Logging.WriteInformation(" " + properties.ListItem["Title"].ToString() + " [sp_Auditlog_Enabled] 1");
Logging.WriteInformation(" Leaving function ActiveAuditLogs");
ActiveSiteClosurePolicy(properties);
});
}
catch (System.IO.FileNotFoundException)
{
Thread.Sleep(10000);
Logging.WriteInformation(" Cannot connect to personal site, reconnecting");
ActiveAuditLogs(properties);
}
catch (Exception eX)
{
Logging.WriteError(properties.ListItem["Title"].ToString() + " " + eX.Message);
Logging.WriteError(eX.StackTrace);
}
}