我有一个使用委托来更新 SharePoint 网站的母版页的方法。我不会详细说明为什么需要这个,但我需要确保该方法在整个过程中同步运行,然后再继续进行下一步。
我怎样才能做到这一点?
代码如下:
[DataContract]
public class CustomerPortalBasicSiteProvider : AbstractProvider<bool>, IExecutable
{
public CustomerPortalBasicSiteProvider()
{
}
List<IProviderSetting> Settings { get; set; }
public bool Execute(ExecuteParams parameters)
{
SetMasterPage(parameters);
return true;
}
private void SetMasterPage(ExecuteParams parameters)
{
// NOTE: I need the contents of this method to run synchronously
SPSecurity.RunWithElevatedPrivileges(
delegate
{
using (var elevatedSite = new SPSite(parameters.SiteUrl))
{
using (var elevatedWeb = elevatedSite.OpenWeb())
{
elevatedWeb.AllowUnsafeUpdates = true;
elevatedWeb.CustomMasterUrl = Settings.Find(x => x.Key == "SPWeb.CustomMasterUrl").Value;
elevatedWeb.Update();
elevatedWeb.AllowUnsafeUpdates = false;
}
}
});
}
}
更新:共享点对象看起来像:
public static class SPSecurity
{
public static AuthenticationMode AuthenticationMode { get; }
public static bool CatchAccessDeniedException { get; set; }
public static bool WebConfigAllowsAnonymous { get; }
public static void RunWithElevatedPrivileges(SPSecurity.CodeToRunElevated secureCode);
[Obsolete("Use SetApplicationCredentialKey method instead.")]
public static void SetApplicationCendentialKey(SecureString password);
public static void SetApplicationCredentialKey(SecureString password);
public delegate void CodeToRunElevated();
public class SuppressAccessDeniedRedirectInScope : IDisposable
{
public SuppressAccessDeniedRedirectInScope();
public void Dispose();
}
}