4

コンソール実行可能ファイルからのコンテキスト トークンを使用して、SharePoint 2013 Online Web サイトに接続しようとしています。しかし、それは私にエラーを与えています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 に接続するにはどうすればよいですか? クレームベース認証のみをサポートしていますか?

4

1 に答える 1

7

認証しようとしている方法は時代遅れだと思います。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

于 2014-03-11T05:58:31.820 に答える