禁用列表通过服务器对象模型限制
-
29-09-2020 - |
题
我想禁用列表通过代码限制,所以我写了以下代码
SPList lstBookings = web.Lists.TryGetList("Bookings");
lstBookings.EnableThrottling = false;
.
但这需要代码在提升权限下运行,因为如果我作为非管理员登录它,它会给我一个错误无法登录。
任何想法?
谢谢。
解决方案
Enablethrottling似乎需要农场管理员权限。查看以下代码:
public bool EnableThrottling
{
get { ... }
set
{
bool nothrottlevalue = !value;
this.SetListNoThrottle(nothrottlevalue);
}
}
internal void SetListNoThrottle(bool nothrottlevalue)
{
SPSite site = this.ParentWeb.Site;
if (!site.WebApplication.Farm.CurrentUserIsAdministrator(true))
SPGlobal.HandleUnauthorizedAccessException(new UnauthorizedAccessException());
else
{ ... }
}
.
系统帐户又具有网站集管理员权限。spsecurity.runwithelevateprivileges允许在应用程序池标识下运行代码,所有站点集合都有相同的站点集管理员权限。
其他提示
将此代码运行为应用程序池标识用户:
SPSecurity.RunWithElevatedPriveleges( () => {
using (var site = new SPSite(SPContext.Current.Site.ID))
{
var web = site.RootWeb;
var lstBookings = web.Lists.TryGetList("Bookings");
lstBookings.EnableThrottling = false;
lstBookings.Update();
}
});
.