簡體   English   中英

System.UnauthorizedAccessException由簡單代碼中的用戶代碼處理

[英]System.UnauthorizedAccessException was unhandled by user code in simple code

我在非常簡單的代碼中得到了這個異常,並且在它周圍具有提升的特權。 在SharePoint 2010中

private void ChangeVersioningOnDocumentLibrary(SPListItem item, SPItemEventProperties properties, SPSite site)
        {
            string sitename = item[MeetingsCommon.Constants.FIELDS_TEXT_TITLE_NAME].ToString();
            string prefix = item[MeetingsCommon.Constants.FIELDS_TEXT_TITLE_NAME].ToString().Substring(0, 2);
            bool isConfirmed = item.TaxonomyFieldValueIsGivenValue(properties.AfterProperties, MeetingsCommon.Constants.FIELDS_MEETINGSTATUS_NAME, MeetingsCommon.Constants.TERMVALUE_MEETINGSTATUS_CONFIRMED, 1033);
            bool isPublished = item.TaxonomyFieldValueIsGivenValue(properties.AfterProperties, MeetingsCommon.Constants.FIELDS_MEETINGSTATUS_NAME, MeetingsCommon.Constants.TERMVALUE_MEETINGSTATUS_PUBLISHED, 1033);

            if (isConfirmed)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPWeb web = site.OpenWeb(prefix + "/" + sitename))
                    {

                            if (web.Exists)
                            {
                                web.AllowUnsafeUpdates = true;
                                SPList agendaPoints = web.GetSafeListByName(MeetingsCommon.Constants.LISTS_AGENDAPOINTS_NAME);
                                agendaPoints.EnableModeration = true;
                                agendaPoints.DraftVersionVisibility = DraftVisibilityType.Author;
                                agendaPoints.Update();
                                web.AllowUnsafeUpdates = false;
                            }

                    }
                });
            }
            if (isPublished)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPWeb web = site.OpenWeb(prefix + "/" + sitename))
                    {                    
                        if (web.Exists)
                        {
                            web.AllowUnsafeUpdates = true;
                            SPList agendaPoints = web.GetSafeListByName(MeetingsCommon.Constants.LISTS_AGENDAPOINTS_NAME);
                            agendaPoints.EnableModeration = false;
                            agendaPoints.DraftVersionVisibility = DraftVisibilityType.Author;
                            agendaPoints.Update();
                            web.AllowUnsafeUpdates = false;
                        }                    
                    }
                });
            }
        }

問題在於,它使用的是來自RunWithElevatedPriviliges外部的spsite對象,該spsite對象必須在內部再次創建才能起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM