【问题标题】:Access denied accessing SharePoint API from within MVC Application访问被拒绝从 MVC 应用程序中访问 SharePoint API
【发布时间】:2011-10-07 15:41:14
【问题描述】:

尝试从 ASP.NET MVC 应用程序中通过 SharePoint API 访问 SharePoint 2010 网站时出现以下错误:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 

MVC 应用程序以 64 位模式托管在 IIS7 上,应用程序池用户是 SharePoint 安装的站点管理员。 重要的是,调用托管在同一个 Web 应用程序中的 SharePoint API 的 WCF 服务可以正常工作,所以我觉得奇怪的是,我无法从控制器操作中获得相同的结果。 p>

我试过了:

  • 设置System.web/identity impersonate="true" etc etc
  • 设置System.web/authentication mode="Windows"
  • 以上的组合。

无论上面尝试了什么,System.Security.Principal.WindowsIdentity.GetCurrent().Name 返回预期的应用程序池用户,但 Request.IsAuthenticated 返回 false。 这通过调试器和事件日志以编程方式验证:

Event code: 4011 
Event message: An unhandled access exception has occurred. 
...
Process information: 
    Process ID: 1234 
    Process name: w3wp.exe 
    Account name: VALIDDOMAIN\VALIDUSER 

Request information: 
    Request URL: http://localhost:2000/Service/ 
    Request path: /Service/ 
    User host address: ::1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: VALIDDOMAIN\VALIDUSER 

如何从标准 MVC3 Web 应用程序控制器操作调用 SharePoint 2010 API?

更新 01:

这是我正在使用的代码:

    using (SPSite site = new SPSite(siteUrl))
    {
        workflow.SPSiteCollectionID = site.ID;

        using (SPWeb web = site.OpenWeb())
        {
            foreach (SPGroup group in web.SiteGroups)
            {
                //some code
            }
        }
    }

这行失败了foreach (SPGroup group in web.SiteGroups)

【问题讨论】:

  • 您的目标是哪个框架? 3.5?
  • .NET 3.5 - 这是我们可以与 SharePoint 2010 API 一起使用的唯一版本。
  • 是的,我知道,这就是我问的原因:P 所以当你构造一个新的 SPSite 对象时会发生访问被拒绝,对吧?您是否尝试过提升权限?另外,在 wcf 服务中,您是否在任何地方(配置/代码)设置了默认(网络)凭据?
  • Naw,它发生在 new SPSite() 之后......请参阅上面的更新。当我尝试遍历 SPWeb.SiteGroups 时会发生这种情况。我也没有在任何地方设置信誉(无论是配置还是代码);请记住,MVC 应用程序将使用与 WCF 服务完全相同的 web.config - 它们都在同一个应用程序中。我没有尝试过 RunWithElevated,因为我不明白为什么我需要这样做,因为 WCF 服务使用相同的代码(实际上,它们都使用相同的 DLL)...
  • 嗯,好吧,这很奇怪......对不起,我想不出别的了,因为 mvc 应用程序和服务共享相同的代码库。

标签: asp.net asp.net-mvc sharepoint sharepoint-2010 sharepoint-api


【解决方案1】:

试试这个: 新 SPSite(siteUrl, SystemAccount.UserToken)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2012-10-14
    • 2014-06-28
    • 1970-01-01
    • 2018-04-06
    • 2016-06-04
    • 1970-01-01
    相关资源
    最近更新 更多