如何将用户凭据从控制台传递到SharePoint Online?
我正在尝试使用控制台可执行文件中的上下文令牌连接SharePoint 2013在线网站。但是,它给了我一个错误如何将用户凭据从控制台传递到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
远程服务器返回了一个错误:(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);