2016-01-13 155 views
2

我試圖登錄到使用Windows集成(NTLM)身份驗證的SharePoint網站。有兩種方法可以輸入SharePoint網站的憑證,Windows身份驗證和表單身份驗證。Sharepoint 2010用戶身份驗證(Windows憑據)與客戶端對象模型

但是,表單身份驗證在此特定網站上處於禁用狀態,我只能使用Windows身份驗證。 有沒有辦法讓我以不同於我登錄Windows機器的憑據登錄本網站?

看到錯誤的位置:Form authentication denied

 String site = "http://sharepoint/"; 
     ClientContext context = new ClientContext(site); 
     context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; 
     FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword"); 
     context.FormsAuthenticationLoginInfo = formsAuthInfo; 

     // The SharePoint web at the URL. 
     Web web = context.Web; 

     // We want to retrieve the web's properties. 
     context.Load(web); 

     // Execute the query to the server. 
     context.ExecuteQuery(); 


     InitializeComponent(); 

我還試圖用: context.Credentials =新的NetworkCredential( 「用戶」, 「合格」,網站);

 ClientContext context = new ClientContext(site); 
     context.Credentials = new NetworkCredential("user", "pass", site); 


     // The SharePoint web at the URL. 
     Web web = context.Web; 

     // We want to retrieve the web's properties. 
     context.Load(web); 

     // Execute the query to the server. 
     context.ExecuteQuery(); 


     InitializeComponent(); 

我碰到下面的401(未授權)error

+0

您尚未提供您迄今嘗試過的任何代碼。你在尋找非代碼解決方案嗎?在Windows 7中,通過按住Shift鍵並右鍵單擊可執行文件,然後選擇「以其他用戶身份運行」,您可以使用不同的Windows憑據運行使用不同Windows憑據的應用程序 – Thriggle

+0

嗨,感謝您的評論。我已經包含了我的代碼。另外,我運行Windows Server 2008 R2 Standard,而不是Windows 7. – Rana

回答

2

而是改變ClientContext對象的AuthenticationMode屬性FormsAuthentication,請嘗試使用對象的Credentials屬性設置爲一個有效的網絡憑證的對象。

ClientContext context = new ClientContext("http://sharepointsite/"); 
context.Credentials = new NetworkCredential("username","password","domain"); 
+0

我試過了,現在我得到401(未經授權的錯誤)。我更新我的帖子 – Rana

+0

Hi @TaimoorRana,「NetworkCredential」構造函數的第三個參數應該是包含帳戶的Active Directory域前綴的字符串值。例如,如果您的登錄名是「MSFT \ RanaTaimoor」,則用戶名是「RanaTaimoor」,域名是「MSFT」 – Thriggle

+0

我的用戶名類似於以下內容:ab12345 - (抱歉,我無法分享確切的用戶名,因爲它是公司帳戶) – Rana

0

不知道,如果它是晚,但默認情況下,託管客戶端對象模型驗證通過使用其Windows憑據(的DefaultCredentials)的用戶。

所以你不需要明確設置證書。只需設置以下內容 -

context.AuthenticationMode = ClientAuthenticationMode.Default; 
相關問題