c# - 如何使用 C# 从 ASP.Net 重置 Active Directory 用户的密码?
问题描述
我要做的是通过填写表格来重置用户的密码,然后单击“更改密码”按钮。
因此,在我的 aspx 页面中,我有 3TextBoxes
个用户名,一个用于密码,一个用于确认密码。
所以基本上它需要找到在文本框中输入的用户名,然后根据在其他两个文本框中输入的内容更改密码。
因此,如果我填写表格并选择“更改密码”,我会收到以下错误:
Exception has been thrown by the target of an invocation.
这是我目前正在使用的代码:
try
{
string strADPath = "LDAP";
string strUsername = "user";
string strPassword = "LDAPPassword";
string userName = txtUserName.Text;
string newPassword = txtNewPassword.Text;
PrincipalContext pc = new PrincipalContext(ContextType.Domain, strADPath, strUsername, strPassword);
UserPrincipal user = UserPrincipal.FindByIdentity(pc, userName);
if (user == null)
{
error.Text = "User name not found in this domain.";
}
user.SetPassword(newPassword);
error.Text = "Password for " + userName + "changed successfully.";
}
catch (Exception ex)
{
// throw exception here
error.Text = ex.Message;
}
不知道为什么我会收到这个错误?
谢谢
解决方案
推荐阅读
- python - 将 emty 列表 `[]` 转换为 `[0]` 熊猫数据框
- reactjs - google 没有在 @react-google-maps/api 的 Gatsby js 应用程序中定义
- jestjs - Jest:编写所有需要首先断言某些步骤的测试的正确方法是什么?
- android - 如何在 MVVM 模型中与服务通信
- python - Python,json,收集哪些数据
- firebase - Flutter/Dart/Firestore:如何将地图列表添加到 Firebase?
- c# - 如何使用 slite-net 在 C# 中忽略列表?
- mongodb - [mongo][replicaset] 升级一个安全的replicaset,不能升级secondary
- mysql - 如何托管和公开我自己的 webapp
- python - Django 个人资料编辑权限