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

问题描述 投票:4回答:1

我正在尝试使用控制台可执行文件中的上下文令牌连接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 sharepoint-online
1个回答
6
投票

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

using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))  
{  
    SecureString passWord = new SecureString();
    clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", 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

© www.soinside.com 2019 - 2024. All rights reserved.