我用管理员设置密码的时候不会报错,用普通用户设置的就报错了:调用的目标发生了异常.
我不知道在哪设置权限。请高人指点下啊,谢谢了!public DirectoryEntry GetUser(string sAMAccountName)
{
DirectoryEntry temp = null;
try
{
DirectoryEntry entry = new DirectoryEntry(ldapPath + ldapDomain, adminName, adminPassword,AuthenticationTypes.Secure); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = ("(objectClass=user)"); foreach (SearchResult resEnt in mySearcher.FindAll())
{
DirectoryEntry de = resEnt.GetDirectoryEntry();
string name = de.Properties[ADUserProperties.sAMAccountName].Value.ToString().ToLower();
if (name == sAMAccountName.ToLower())
{
temp = resEnt.GetDirectoryEntry();
break;
}
}
}
catch
{ }
return temp;
} public bool SetPassword(ADUserInfos adUser)
{
bool isSuccess = false;
try
{
DirectoryEntry user = GetUser(adUser.SAMAccountName); // 模拟超级管理员,以达到有权限修改用户密码,这个模拟加和没加一个样。
NtsIdentityImpersonation impersonate = new NtsIdentityImpersonation(AdminName, AdminPassword, LdapDomainName);
impersonate.BeginImpersonate(); user.Invoke("SetPassword", new object[] { adUser.PassWord }); impersonate.StopImpersonate(); user.Close();
//user.Invoke("SetPassword", adUser.PassWord);
//user.CommitChanges();
isSuccess = true;
}
catch
{ }
return isSuccess;
}
我不知道在哪设置权限。请高人指点下啊,谢谢了!public DirectoryEntry GetUser(string sAMAccountName)
{
DirectoryEntry temp = null;
try
{
DirectoryEntry entry = new DirectoryEntry(ldapPath + ldapDomain, adminName, adminPassword,AuthenticationTypes.Secure); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = ("(objectClass=user)"); foreach (SearchResult resEnt in mySearcher.FindAll())
{
DirectoryEntry de = resEnt.GetDirectoryEntry();
string name = de.Properties[ADUserProperties.sAMAccountName].Value.ToString().ToLower();
if (name == sAMAccountName.ToLower())
{
temp = resEnt.GetDirectoryEntry();
break;
}
}
}
catch
{ }
return temp;
} public bool SetPassword(ADUserInfos adUser)
{
bool isSuccess = false;
try
{
DirectoryEntry user = GetUser(adUser.SAMAccountName); // 模拟超级管理员,以达到有权限修改用户密码,这个模拟加和没加一个样。
NtsIdentityImpersonation impersonate = new NtsIdentityImpersonation(AdminName, AdminPassword, LdapDomainName);
impersonate.BeginImpersonate(); user.Invoke("SetPassword", new object[] { adUser.PassWord }); impersonate.StopImpersonate(); user.Close();
//user.Invoke("SetPassword", adUser.PassWord);
//user.CommitChanges();
isSuccess = true;
}
catch
{ }
return isSuccess;
}
解决方案 »
- 求写一个函数,来防SQL注入漏洞
- Gridview BoundField 内容修改,蔡鸟问题,请大家解答!
- 在JSP中可以配置一个Serverlet随着WEB服务的启动而马上启动,在IIS中如何使一个WEB应用程序在IIS服务启动时即开始运行,而不是在有第一个客户端访问之后才开始运行!
- 急,大哥们来救命!!
- ~~~懂的FLASH连接.NET的朋友,请指点一下 回复着都有分相赠!~!!!
- sql使用事务的问题!
- ipcchannel使用事件出现问题,why???
- 用户控件不响应任何事件?!!!
- (控制页面闪动和得到对话框的返回值)?????????
- 请教:在水晶报表中怎么动态的加载数据
- 发送邮件的问题 急 急 急
- 关于html导出excel的时候能否变成多个sheet
同志们顶顶啊
new object[] 是为什么呢
为什么 new object[] 呢
查看具体的 错误 继续 断点
在web.config里面的<authentication mode="Windows" />底下加
<identity impersonate="true" userName="YourAdminUsr" password="YourAdminPwd"/>