基本上我想顯示來自azure AD的用戶的各個領域。 我能夠顯示除signInName之外的所有字段。 登錄屬性的類型爲: IList IUser.SignInNames {get;}這就是爲什麼我的邏輯不工作,因爲我正在使用一個console.writeline()。編輯1:顯示登錄從Azure AD
下面是我的代碼:
private static async Task PeoplePickerExample(IActiveDirectoryClient client, string searchString)
{
List<IUser> usersList = null;
IPagedCollection<IUser> searchResults = null;
try
{
IUserCollection userCollection = client.Users;
searchResults = await userCollection.Where(user =>
user.UserPrincipalName.StartsWith(searchString) ||
user.DisplayName.StartsWith(searchString) ||
user.GivenName.StartsWith(searchString) ||
user.Surname.StartsWith(searchString)).Take(10).ExecuteAsync();
usersList = searchResults.CurrentPage.ToList();
}
catch (Exception e)
{
Program.WriteError("\nError getting User {0}", Program.ExtractErrorMessage(e));
}
if (usersList != null && usersList.Count > 0)
{
do
{
int index = 1;
usersList = searchResults.CurrentPage.ToList();
foreach (IUser user in usersList)
{
IUserFetcher userFetcher = user as IUserFetcher;
IDirectoryObject manager = await userFetcher.Manager.ExecuteAsync();
IPagedCollection<IDirectoryObject> reports = await userFetcher.DirectReports.ExecuteAsync();
Console.WriteLine("Sign in name:{0}", user.SignInNames);
Console.WriteLine("Manager:" + ((IUser)(manager)).DisplayName);
Console.WriteLine("Country:{0}", user.Country);
Console.WriteLine("Mail Nickname:{0}", user.MailNickname);
index++;
}
searchResults = await searchResults.GetNextPageAsync();
} while (searchResults != null);
}
else
{
Console.WriteLine("User not found");
}
}
請檢查在這裏我用這個行: Console.WriteLine( 「登錄名:{0}」,user.SignInNames);
那麼我如何獲取corpnet或microsoft用戶的signinname?我應該使用哪些財產? – dotnetman
你的名字是什麼意思?我們可以使用UserPrincipalName來顯示登錄電子郵件,或使用顯示名稱/名字和姓氏顯示其登錄名。你使用B2C租戶嗎? –
Hello Jambor, 感謝您的回覆。是的,我使用B2C租戶。我認爲上述代碼的問題是我顯示signinName的方式。我認爲問題在於類型。它是IList Iuser登錄名。我認爲我們需要在控制檯上以不同的方式顯示它? –
dotnetman