我正在尝试通过 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);
}
}
需要更多详细信息才能完全理解问题,例如您得到的响应。有什么错误吗?
但是,我注意到您没有使用“ await ”关键字。
尝试这个:
var response = await graphServiceClient.Users[currentUser[0].Id]
.Request()
.UpdateAsync(user);
很可能您的用户“UpdateAsync(user)”操作没有被执行,因为您没有等待“Request()”操作。所以,更新永远不会发生。
同样,需要更多细节才能完全了解正在发生的事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句