激活站点功能时,我会自动设置 WebApplication 属性。这是代码:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb currentWeb = ContentTypes.ValidateFeatureActivation(properties);
using (SPSite site = new SPSite(currentWeb.Site.Url))
{
SPWebApplication currentApplication = site.WebApplication;
if (currentApplication.MaxQueryLookupFields < 20)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
currentApplication.MaxQueryLookupFields = 20;
}
catch (System.Security.SecurityException ex)
{
_log.ErrorFormat("no permission");
}
});
}
}
}
即使我是农场管理员激活了该功能,也会引发安全异常(“拒绝访问”)。在线
currentApplication.MaxQueryLookupFields = 20;
AFAIK SPSecurity.RunWithElevatedPrivileges 作为站点管理员而不是场管理员运行。但如何做到这一点?(没有 RunWithElevatedPrivileges 我得到了同样的例外。