Asp.net 由于域控制器的原因,DirectoryEntry无法更改密码。帮忙?
假设这是ASP.NET中使用DirectoryServices的基本密码更改方法 守则:Asp.net 由于域控制器的原因,DirectoryEntry无法更改密码。帮忙?,asp.net,web-services,directoryservices,change-password,Asp.net,Web Services,Directoryservices,Change Password,假设这是ASP.NET中使用DirectoryServices的基本密码更改方法 守则: String path = ConfigurationManager.AppSettings["LDAPServer"] + myDN; DirectoryEntry de = new DirectoryEntry(path, @"Domain A\" + myUserId, myPassword, AuthenticationTypes.Secure); de.Invoke("ChangePassword
String path = ConfigurationManager.AppSettings["LDAPServer"] + myDN;
DirectoryEntry de = new DirectoryEntry(path, @"Domain A\" + myUserId, myPassword, AuthenticationTypes.Secure);
de.Invoke("ChangePassword", new object[] { myPassword, myNewPassword});
如果我通过虚拟IIS(使用VisualStudio)在本地运行,则运行良好。
但是,如果我将此发布到生产,我会得到:
无法从域控制器读取配置信息,原因可能是计算机不可用,或者访问被拒绝。(来自HRESULT的异常:0x80070547)
这两者之间的唯一区别可能是我的计算机位于域A上,而发布的服务器位于域B上。
域A和域B是受信任的,域A是域B的父级
有人知道错误是在哪里以及如何产生的吗
编辑:也许我应该补充一点,这是一个Web服务。另一个应用程序将抛出必要的信息进行验证,Web服务将更改密码。好吧,我为解决上述问题所做的工作如下:
private bool ResetDomainAccountPassword(string loginName, string oldPassword, string newPassword)
{
DirectoryEntry e2 = new DirectoryEntry();
try
{
// ----- Get the credentials for the active directory service account.
string userName = ServiceUser();
string password = ServicePassword();
using (DirectoryEntry e = new DirectoryEntry(Path(), userName, password, AuthenticationTypes.Secure))
{
string search = string.Format("(sAMAccountName={0})", loginName);
DirectorySearcher s = new DirectorySearcher(e, search);
SearchResult sr = s.FindOne();
if (sr != null)
{
e2 = sr.GetDirectoryEntry();
e2.Username = userName;
e2.Password = password;
}
if (e2.NativeGuid != null)
{
return ResetPassword(e2, oldPassword, newPassword);
}
else
return false;
}
}
catch (Exception ex)
{
Exception inner = ex.InnerException;
// ----- Handle exception here.
return false;
}
finally
{
e2.Dispose();
}
}
重置密码方法
private bool ResetPassword(DirectoryEntry e, string oldPassword, string newPassword)
{
try
{
ActiveDs.IADsUser u = e.NativeObject as ActiveDs.IADsUser;
Type t = e.NativeObject.GetType();
if (u.IsAccountLocked)
{
u.IsAccountLocked = false;
u.SetInfo();
}
u.SetPassword(newPassword);
u.SetInfo();
e.CommitChanges();
return true;
}
catch (Exception ex)
{
Exception inner = ex.InnerException;
// ----- Handle exception here.
return false;
}
}
有一件事我忘记了:您需要添加对“活动DS类型库”(COM)的引用。很抱歉将您的标记为答案并将其删除。事实上,由于身份问题,我又犯了一个错误,我认为这个问题已经解决并转移到下一个问题 无论如何,我已经通过更改DirectoryEntry的路径解决了这个问题。 在此之前: LDAP://server.domain/distrignizedName 但我把它改成了 LDAP://区分名称
然后一切正常。生产IIS仅使用“Windows身份验证”运行?是的,这是唯一勾选的框。
在web.config中?我尝试了使用和不使用它,错误消息相同。另外,我对我的帖子做了一个小编辑,表明这是一个Web服务。嗯。。很抱歉,看起来模拟正在抛出“拒绝访问”错误,但来自代码的其他部分。让我看看firstOk,在打开模拟之后,当它试图运行一个进程时,它会抛出拒绝访问错误。你知道如何应对吗?