【问题标题】:How do I pass user credentials from the console to SharePoint Online?如何将用户凭据从控制台传递到 SharePoint Online?
【发布时间】:2014-04-14 08:18:23
【问题描述】:

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

这里是sn-p的代码:

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】:

    我认为您尝试进行身份验证的方法已经过时。 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();
    } 
    

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

    【讨论】:

    • 在passWord对象中创建密码:foreach(char c in "yourpassword".ToCharArray()) passWord.AppendChar(c);
    猜你喜欢
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多