在我的eventreceiver项目中,itemAdded函数,我的代码将向第二个列表中添加项目,但它对于一些低权限的用户不起作用
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb(properties.Web.ID))
{
web.AllowUnsafeUpdates = true;
//my code
web.AllowUnsafeUpdates = false;
}
}
}发布于 2019-07-05 04:37:14
获取SPList对象时,请务必使用提升的web。不使用当前SPContext或事件接收器属性中的SPWeb。
因此,在您的示例中,获取列表应该如下所示:
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb(properties.Web.ID))
{
web.AllowUnsafeUpdates = true;
SPList someList = web.Lists.tryGetList("LISTNAME");
SPListItem newItem = someList.AddItem();
// .... update columns and newItem.Update()
web.AllowUnsafeUpdates = false;
}
}
}如果这不能解决问题,请提供更多的代码来检查,也许还有出现的错误。
发布于 2019-07-05 23:44:27
我写了一些代码(LogInfo("event@receiver@ starting!");)来记录我的代码中发生了什么,令人惊讶的是我发现甚至ItemAdded函数的第一行都没有执行!因为在shapreoint logs.It中没有找到任何东西,这意味着它没有进入ItemAdded函数或其他函数。下面是我的代码:
public override void ItemAdded(SPItemEventProperties properties)
{
LoLogInfo("event@receiver@ starting!");
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
LogInfo("event@receiver@ first step!");
using (SPSite site = new SPSite(properties.SiteId))
{
LogInfo("event@receiver@ second step!");
using (SPWeb web = site.OpenWeb(properties.Web.ID))
{
LogInfo("event@receiver@ third step!");
SPList activeList = web.Lists.TryGetList(properties.List.Title);
SPList finalList = web.Lists[FinalListName];
web.AllowUnsafeUpdates = true;
SPListItem finalListItem = finalList.AddItem();
LogInfo("event@receiver@ forth step!");
//some other code here
web.AllowUnsafeUpdates = false;
}
}
});
}https://stackoverflow.com/questions/56892124
复制相似问题