如何将用户凭据从控制台传递到 SharePoint Online?

2024-01-03

我正在尝试使用控制台可执行文件中的上下文令牌连接 SharePoint 2013 Online 网站。但是,它给了我错误The remote server returned an error: (403) Forbidden.

这是代码片段:

string spurl = ConfigurationManager.AppSettings["Sharepoint_URL"].ToString();
using (ClientContext context = new ClientContext(spurl))
{
    context.Credentials = new NetworkCredential("username", "password", "domain");
    context.ExecuteQuery();
    Web web = context.Web;
    context.Load(web);
    context.ExecuteQuery();
    Console.WriteLine(context.Web.Title);
 }               
 Console.ReadKey();

如何与 SharePoint Online 建立连接?它只支持基于声明的身份验证吗?


我认为您尝试进行身份验证的方法已经过时了。 SharePoint 2013 客户端对象模型现在有一个名为SharePointOnlineCredentials它抽象出了所有繁琐的 cookie 容器内容。例如。:

using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))  
{  
    SecureString passWord = new SecureString();
    clientContext.Credentials = new SharePointOnlineCredentials("[email protected] /cdn-cgi/l/email-protection", passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    Console.WriteLine(web.Title);
    Console.ReadLine();
} 

请参阅此链接了解更多信息:https://sharepoint.stackexchange.com/questions/83985/access-the-sharepoint-online-webservice-from-a-console-application https://sharepoint.stackexchange.com/questions/83985/access-the-sharepoint-online-webservice-from-a-console-application

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将用户凭据从控制台传递到 SharePoint Online? 的相关文章

随机推荐