System.UnauthorizedAccessException未被简单代码中的用户代码处理

时间:2013-03-21 08:48:25

标签: c# sharepoint sharepoint-2010

我在非常简单的代码中得到了这个异常,并且我在它周围运行了提升权限。 它在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;
                        }                    
                    }
                });
            }
        }

1 个答案:

答案 0 :(得分:0)

问题是它使用的是来自RunWithElevatedPriviliges外部的spsite对象,必须在内部再次创建spsite对象才能使其工作。