Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将用户凭据从控制台传递到SharePoint Online?_Sharepoint_Sharepoint Online - Fatal编程技术网

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

如何将用户凭据从控制台传递到SharePoint Online?,sharepoint,sharepoint-online,Sharepoint,Sharepoint Online,我正在尝试使用控制台可执行文件中的上下文令牌连接SharePoint 2013在线网站。但是,它给了我一个错误远程服务器返回了一个错误:(403)禁止。 以下是代码片段: string spurl = ConfigurationManager.AppSettings["Sharepoint_URL"].ToString(); using (ClientContext context = new ClientContext(spurl)) { context.Credentials = n

我正在尝试使用控制台可执行文件中的上下文令牌连接SharePoint 2013在线网站。但是,它给了我一个错误
远程服务器返回了一个错误:(403)禁止。

以下是代码片段:

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("loginname@yoursite.onmicrosoft.com", passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    Console.WriteLine(web.Title);
    Console.ReadLine();
} 

有关详细信息,请参阅此链接:

在密码对象中创建密码:foreach(在“yourspassword.ToCharArray()中的字符c)password.AppendChar(c);