簡體   English   中英

無法使用Sharepoint客戶端對象模型連接到Sharepoint網站

[英]Unable to connect to sharepoint site using Sharepoint Client Object Model

我試圖編寫一個控制台應用程序以連接到我們的SharePoint應用程序站點之一。 我正在運行一個基本示例以確保連接性。 程序不斷失敗,並出現以下錯誤:遠程服務器返回錯誤:(500)Internal Server Error。

狀態:System.Net.WebExceptionStatus.ProtocolError

我無權訪問IIS服務器來檢查日志。 我的代碼如下:

        string siteUrl = "http://spsiteurl/";


        ClientContext clientContext = new ClientContext(siteUrl);
        clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
        clientContext.Credentials = new NetworkCredential("...", "...", "...");

        Web oWebsite = clientContext.Web;

        clientContext.Load(oWebsite,
            w => w.Title);

        clientContext.ExecuteQuery();

        Console.WriteLine(oWebsite.Title);

關於我可能會出錯的任何方向?

嘗試下面的代碼

    ClientContext context = new ClientContext("https://test.com/");
    System.Net.ServicePointManager.ServerCertificateValidationCallback =
        ((sender, certificate, chain, sslPolicyErrors) => true);

    string strUserName = @"abc";
    string strPassword = "pwd";
    var credentials = new NetworkCredential(strUserName, strPassword);
    Web web = context.Web;
    context.Load(web, w => w.Title);
    context.Credentials = credentials;
    context.ExecuteQuery();


    // Now, the web's properties are available and we could display 
    // web properties, such as title. 
    System.Console.WriteLine("Web Title");
    System.Console.WriteLine(web.Title);

它將在控制台中正常工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM