我想通过单点登录将 SharePoint Online 与 .NET 上的当前用户连接。我不想在代码中指定用户名和密码。不幸的是,我在
ExecuteQuery()
上收到以下错误消息:
远程服务器返回错误:(403) Forbidden
我的代码:
string siteCollectionUrl = "https://xxx.sharepoint.com/teams/yyyy";
System.Net.ICredentials credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
SharePoint.ClientContext context = new SharePoint.ClientContext(siteCollectionUrl);
context.Credentials = credentials;
SharePoint.Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
string tt = web.Title;
如何解决此错误?
Microsoft.SharePoint.Client.SharePointOnlineCredentials
类进行身份验证。
像这样:
String name = "[email protected]";
String password = "xxxx";
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
securePassword.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(name, securePassword);
string siteCollectionUrl = "https://xxx.sharepoint.com/teams/yyyy";
ClientContext ctx = new ClientContext(siteCollectionUrl );
ctx.Credentials = credentials;