问题
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();
}
I'm trying to login on a sharepoint web site.
This code is what i could come up with.
No matter what i do, i'll get the Not authorized (401)
But if i type the exactly same in my browser, it's working fine..
Can anyone see the problem?
回答1:
make your code simple ;) use this codes:
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();
}
来源:https://stackoverflow.com/questions/36424603/c-sharp-windows-application-sharepoint-login