GuaranteeUser()将返回以下错误“找不到指定的用户." [英] EnsureUser() will return the following error “The specified user could not be found.”

查看:63
本文介绍了GuaranteeUser()将返回以下错误“找不到指定的用户."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在内部SharePoint 2013中构建事件接收器,现在在事件接收器中,我从名为"User"的下拉列表中检索表示用户名的字符串,例如(User.ABC) ; OrderAssignToApprover",那么我就是 如下所示,使用GuaranteeUser()将字符串转换为SPUser:-

I am working on building an event receiver inside my sharepoint on-premises 2013, Now inside the event receiver i am retrieving a string representing a user name such as (User.ABC) from a drop down list named "OrderAssignToApprover", then i am converting the string to a SPUser using EnsureUser(), as follow:-

string approver = currentItem["OrderAssignToApprover"].ToString();
SPUser spUser = properties.Site.RootWeb.EnsureUser(approver);

以上内容对所有用户都适用,除了单个用户,我在这里遇到此异常:-

The above is working well for all the users except for a single user, where i am getting this exception :-

The specified user User.ABC could not be found. 

现在我虽然该用户帐户已从AD中删除或已被禁用,等等.但是当我尝试将该用户添加到共享点安全组时,或者当我尝试将该用户添加到人员或组"列中时,能够做到这一点而没有任何问题..看来 该帐户还可以,但是为什么SecureUser返回上面的错误?同样,当我检查网站集的隐藏用户列表时,用户名在那里,但是从他的Skype for Buisness状态显示,该用户已脱机大约20天, 如下:-

now i though that the user account has been removed from AD or has been disabled , etc.. but when i try to add this user to a sharepoint security group or when i try adding him to a People or Group column i was able to do so without any problem.. so seems the account is fine ,, but why EnsureUser is returning the above error? also when i check the site collection's hidden user list the user name is there, but from his Skype for Buisness status it is showing that the user has been offline for around 20 days, as follow:-

那么这可能是问题吗?

推荐答案

您可以检查值currentItem ["OrderAssignToApprover"].ToString();

You can check the value currentItem["OrderAssignToApprover"].ToString();

格式为userid; #username.

The format is userid;#username.

您应该使用currentItem ["OrderAssignToApprover"].ToString().Split('#')[1]来获取用户名.

You should currentItem["OrderAssignToApprover"].ToString().Split('#')[1] to get the username.

将代码更改为

SPUser spUser = properties.Site.RootWeb.EnsureUser(approver.Split('#')[1]);

SPUser spUser = properties.Site.RootWeb.EnsureUser(approver.Split('#')[1]);


这篇关于GuaranteeUser()将返回以下错误“找不到指定的用户."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆