簡體   English   中英

C# Windows 應用程序 SharePoint 登錄

[英]C# Windows Application SharePoint Login

string urlSite = "https://intranet.site.dk";
string user = "myuser@vid.net.local";
string pwd = "mypass";

using (ClientContext clientContext = new ClientContext(urlSite))
{
    SecureString passWord = new SecureString();
    foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
    clientContext.Credentials = new SharePointOnlineCredentials(user, passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    Console.WriteLine(web.Title);
    Console.ReadLine();
}

我正在嘗試登錄一個 sharepoint 網站。
這段代碼是我能想到的。
無論我做什么,我都會得到未授權 (401)
但是如果我在瀏覽器中輸入完全相同的內容,它就可以正常工作..
任何人都可以看到問題嗎?

使您的代碼簡單 ;) 使用以下代碼:

using (ClientContext clientContext = new ClientContext(urlSite))
            {
                clientContext.Credentials = new NetworkCredential(user, pwd, domain);
                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();
                Console.WriteLine(web.Title);
                Console.ReadLine();
            }

暫無
暫無

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

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