C# &引用;编码的;SharePoint客户端对象模型中的登录名
我正在编写一个小型的.NET概念验证控制台应用程序,它在SharePoint文档库上执行一系列操作。我注意到以下方法需要一个“编码”的登录名,即包含提供者信息的登录名,例如C# &引用;编码的;SharePoint客户端对象模型中的登录名,c#,.net,sharepoint-2013,sharepoint-api,sharepoint-clientobject,C#,.net,Sharepoint 2013,Sharepoint Api,Sharepoint Clientobject,我正在编写一个小型的.NET概念验证控制台应用程序,它在SharePoint文档库上执行一系列操作。我注意到以下方法需要一个“编码”的登录名,即包含提供者信息的登录名,例如I:0#.w | DOMAIN\user context.Web.EnsureUser(encodedLoginName); context.Web.SiteUsers.GetByLoginName(encodedLoginName); 如何可靠地将DOMAIN\user等用户名转换为SharePoint客户端对象模型中的此
I:0#.w | DOMAIN\user
context.Web.EnsureUser(encodedLoginName);
context.Web.SiteUsers.GetByLoginName(encodedLoginName);
如何可靠地将DOMAIN\user
等用户名转换为SharePoint客户端对象模型中的此编码格式
我已经阅读了一篇关于使用
SPClaimProviderManager
解决此问题的文章,该工具在客户端API中不可用。我可以使用实用程序方法获取编码的登录名:
using SP = Microsoft.SharePoint.Client;
//...
// resolve user principal using regular login name or e-mail:
var userPrincipal = SP.Utilities.Utility.ResolvePrincipal(
context,
context.Web,
"DOMAIN\\user", // normal login name
SP.Utilities.PrincipalType.User,
SP.Utilities.PrincipalSource.All,
context.Web.SiteUsers,
false);
context.ExecuteQuery();
// ensure that the user principal was resolved:
if (userPrincipal.Value == null)
throw new Exception("The specified user principal could not be resolved");
// get a User instance based on the encoded login name from userPrincipal
var user = context.Web.SiteUsers.GetByLoginName(userPrincipal.LoginName);
context.Load(user);
context.ExecuteQuery();
这似乎是有意的。但是,如果有更好的方法或注意事项需要注意,请告诉我。只有当我在第三个参数中使用电子邮件地址而不是登录名(域\别名)并且在方法ResolvePrincipal()中将最后一个参数设置为true而不是false时,这才对我有效.My
ClientContext
没有context.Web.SiteUsers
?。此方法是否允许您将声明令牌解码为域\用户?