SharePoint 2013 - System.UnauthorizedAccessException:拒绝访问

时间:2014-05-10 13:43:24

标签: c# sharepoint sharepoint-2013 access-denied

当我尝试在我的网络服务中创建文件夹/项目时出现以下错误消息,请问您的建议吗?

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex)
   at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem …… (SKIP)

使用本地管理员帐户(也是网站集管理员

)的Web服务(应用程序池和传递身份验证)

我的服务器信息如下: - Windows Server 2012 - SharePoint 2013 - SQL Server 2012

Web服务.NET版本(4.0)

Web服务代码(用于测试):

使用委托(如果注释掉仍然无法正常工作" RunWithElevatedPrivileges"):

public string TestCreateFolderTestingElevatedSecurity()
        {

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                using (SPSite oSPsite = new SPSite(strSharePointSite))//http://localhost
                {
                    oSPsite.AllowUnsafeUpdates = true;

                    using (SPWeb oSPWeb = oSPsite.OpenWeb())
                    {
                        oSPWeb.AllowUnsafeUpdates = true;

                        /* Path within the list where the new folder gets created
                           Leave it empty if it needs to be created under root */
                        String nodeDepthPath = @"";

                        /* get the list instance by name */
                        SPList list = oSPWeb.Lists.TryGetList(strTestDocLib);//DocumentLibrary

                        /* create a folder under the path specified */
                        SPListItem folderItem = list.Items.Add(
                            list.RootFolder.ServerRelativeUrl + nodeDepthPath,
                            SPFileSystemObjectType.Folder, strNewFolderName);//FolderName

                        /* set the folder name and update */
                        folderItem.Update();

                        oSPWeb.AllowUnsafeUpdates = false;
                    }

                    oSPsite.AllowUnsafeUpdates = false;
                }
            });
            return "Success";
        }

非常感谢你的关注。

1 个答案:

答案 0 :(得分:0)

此问题适用于SP 2013&网页服务。相同的代码适用于SP 2010.要解决此问题,请使用 Win32 API 模拟。看看这篇文章的答案 - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/6c306583-5d90-49e7-a213-c0410b705b27/impersonation-not-working-in-sharepoint-web-service