在Web部件中,沒有任何權限的用戶需要讀取和更新Sharepoint列表。使用提升的權限更新Sharepoint列表
提升權限適用於閱讀列表,但是當我嘗試更新同一列表時,將引發異常。如何以更高的權限更新列表?
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite oSite = SPControl.GetContextSite(HttpContext.Current);
SPWeb oWeb = oSite.OpenWeb();
oWeb.AllowUnsafeUpdates = true;
SPListItemCollection listItems = oWeb.Lists["nameList"].Items;
SPListItem item = listItems.Add();
...
item.Update(); // Throws Exception
});
異常發送一個「不能達到引起斷章取義跟蹤」的消息。 – 2011-05-18 12:20:31
我建議使用在正確的代碼中使用,你不應該放棄spsite和spweb對象。如果你沒有直接從spcontext獲得它,或者你的代碼寫在正確的代碼上面 – 2011-05-19 05:49:20
基本上是一個副本。看看這個答案:http://stackoverflow.com/questions/6043312/sharepoint-query-with-elevated-privileges – trgraglia 2011-05-18 13:32:30