2015-12-21 75 views
0

我試圖從Office 365網站檢索一些信息。我在執行調用時遇到了不一致的403錯誤。這種情況不規則地發生,並由IISReset解決。請幫忙。Client.executeQuery()發生403錯誤

ClientContext clientContext = new ClientContext(Constants.SP_URL); 
      { 
       SecureString passWord = new SecureString(); 
       foreach (char c in Constants.SP_SERVICE_PASS.ToCharArray()) passWord.AppendChar(c); 
       var cred = new SharePointOnlineCredentials(Constants.SP_SERVICE_ACC, passWord); ; 
       clientContext.Credentials = new SharePointOnlineCredentials(Constants.SP_SERVICE_ACC, passWord); 


        Web web = clientContext.Web; 

        string docLibraryName = Constants.SP_PUBLISHED_LIB; 
        var list = clientContext.Web.Lists.GetByTitle(docLibraryName); 
        clientContext.Load(list); 
        **clientContext.ExecuteQuery();** 

回答

0

這裏是你需要獲得一個客戶端上下文並加載您data.This驗證你對SP在線Office 365中我不知道你會怎麼說我重置我的IIS什麼。這不適用,除非連接到本地SP實例。

private void AutheticateO365(string url, string password, string userName) 
{ 
    Context = new ClientContext(url); 
    var passWord = new SecureString(); 
    foreach (char c in password.ToCharArray()) passWord.AppendChar(c); 
    Context.Credentials = new SharePointOnlineCredentials(userName, passWord); 
    var web = Context.Web; 
    Context.Load(web); 
    Context.ExecuteQuery(); 
}