gpt4 book ai didi

c# - 从 SharePoint 中托管的 WCF 服务访问 SPFarm PropertyBag 时出现 SecurityException

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:07 24 4
gpt4 key购买 nike

我使用 this tutorial 在 SharePoint 2010 (basicHttpBinding) 中托管了一个 WCF 服务.程序集部署到 GAC 并包含 WCF 服务和计时器作业。两者调用相同的方法。 timerjob 工作成功。

但是当我调用 WCF 服务的方法时,我得到一个异常,它不能在 SPFarm PropertyBag 中写入属性。

System.Security.SecurityException: Access denied.
at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
at Microsoft.SharePoint.Administration.SPFarm.Update()
at MyCompany.MyProduct.Business.Config.SetPropertyValue(IPropertyBag propertyBag, String propertyName, String value)
The Zone of the assembly that failed was:
MyComputer

我尝试使用农场管理员帐户调用该方法并尝试使用 SPSecurity.RunWithElevatedPrivileges,但没有成功。

我在提升权限 block 的内部和外部检查了 WindowsIdentity.GetCurrent(),外部是调用者用户,内部是 WebApplications AppPool 的用户

因此正确模拟了 AppPool 用户,但 SharePoint 2010“disallows modification ... to all objects inheriting from SPPersistedObject in the Microsoft.SharePoint.Administration namespace ... from content web applications

文章说,有一个开关 SPWebService.ContentService.RemoteAdministratorAccessDenied(命名空间 Microsoft.SharePoint.Administration)可以消除这种行为,但我不能依赖管理员使用它来运行我的解决方案.

所以我仍然没有解决方案

最佳答案

我找到了解决该问题的技巧。我不会使用它,因为它真的很脏,但也许有人需要它,所以:

  1. 不要通过普通的 Web 应用程序 URL 调用 WCF 服务。使用中央管理的 URL(例如 http://myserver:9999/_vti_bin/project/myservice.svc)
  2. 运行以提升的权限 (SPSecurity.RunWithElevatedPrivileges) 更改农场属性的部分。
  3. 在提升部分之前(现在它真的很脏)设置 System.Web.HttpContext.Current.Items["FormDigestValidated"] = true;

正如我所说,不是很好,但工作...

关于c# - 从 SharePoint 中托管的 WCF 服务访问 SPFarm PropertyBag 时出现 SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3958548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com