我是 sharepoint 2010 的新手。我想限制用户更改主题,而不是使用 sharepoint 2010 中的功能的站点管理员。我尝试了下面的代码来做同样的事情。
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
SPPolicyRole RestrictThemes;
//we are removing the ApplyStyleSheets permission and ApplyThemeAndBorder permission by passing this
//to Policyroles.
SPBasePermissions RestrictPermissions = SPBasePermissions.ApplyStyleSheets | SPBasePermissions.ApplyThemeAndBorder;
//we are not granting any permissions
SPBasePermissions GrantPermissions = new SPBasePermissions();
RestrictThemes = webApp.PolicyRoles["Restrict Themes"];
if (RestrictThemes == null)
{
RestrictThemes = webApp.PolicyRoles.Add("Restrict Themes", "Restricts themes to be modified by anybody",
GrantPermissions,
RestrictPermissions);
webApp.Update();
}
SPPolicy policy = webApp.Policies.Add("NT Authority\\Authenticated users", "All Authenticated Users");
policy.PolicyRoleBindings.Add(RestrictThemes);
webApp.Update();
});
但是当我尝试这段代码时,它甚至不允许网站管理员。请提供任何想法或建议。
提前致谢。