当试图从ASP内通过SharePoint API访问SharePoint 2010站点时,我得到以下错误。. NET MVC应用程序:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
MVC应用程序以64位模式托管在IIS7上,应用程序池用户是SharePoint安装的站点管理员。重要的是,在同一个web应用程序中调用SharePoint API的WCF服务没有任何问题,所以我发现很奇怪,我不能从控制器操作中获得相同的结果。
I have try:
- 设置
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: VALIDDOMAINVALIDUSER
Request information:
Request URL: http://localhost:2000/Service/
Request path: /Service/
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: VALIDDOMAINVALIDUSER
如何从标准的mvc 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)
试试这个:新建SPSite(siteUrl, SystemAccount.UserToken)