我正在嘗試通過 Microsoft Graph 重置用戶密碼,代碼運行但用戶密碼未更改。我的代碼基于以下檔案:https ://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=csharp
string GeneratedPassword = "Testing@12345";
//GeneratedPassword = letterOne PasswordGenerator.Generate(8, 3) $"{letterTwo}{NumberOne}";
var currentUser = users.Where(x => x.Mail == accountEmail).ToArray();
if (currentUser.Length!=0)
{
Console.WriteLine(currentUser[0].Id);
try
{
var user = new User
{
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = false,
Password = GeneratedPassword
}
};
var response = graphServiceClient.Users[currentUser[0].Id]
.Request()
.UpdateAsync(user);
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
uj5u.com熱心網友回復:
需要更多詳細資訊才能完全理解問題,例如您得到的回應。有什么錯誤嗎?
但是,我注意到您沒有使用“ await ”關鍵字。
嘗試這個:
var response = await graphServiceClient.Users[currentUser[0].Id]
.Request()
.UpdateAsync(user);
很可能您的用戶“UpdateAsync(user)”操作沒有被執行,因為您沒有等待“Request()”操作。所以,更新永遠不會發生。
同樣,需要更多細節才能完全了解正在發生的事情。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490703.html
上一篇:ASP.NETMVC將RememberMe復選框添加到@modelAuthenticationScheme[]
下一篇:為什么InvocationExpression的引數是Expression而不是ParameterExpression?
