饮酒买醉

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  9 随笔 :: 15 文章 :: 9 评论 :: 1 Trackbacks
using System.DirectoryServices;

try
            
{

                
string sAMAccountName = "xingtingting";
                
string newPassword = "12345678";
                
//iw.local/OU=HXZ,
                DirectoryEntry de = new DirectoryEntry("LDAP://iw.local/OU=HXZ,DC=iw,DC=local","iw\\spsadmin","iswind",AuthenticationTypes.Sealing );
                DirectorySearcher deSearch 
= new DirectorySearcher(de);
                deSearch.Filter    
= "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + sAMAccountName    + "))";
                deSearch.SearchScope 
= SearchScope.Subtree;
                SearchResult result    
= deSearch.FindOne();
                de 
= new DirectoryEntry(result.Path);
                de.Invoke(
"SetPassword"new object[]{newPassword});
                de.CommitChanges();
                de.Close();

                System.Windows.Forms.MessageBox.Show(
"修改成功!");

            }

            
catch (Exception ex)
            
{
                
throw ex;
            }
执行至:de.Invoke("SetPassword",new object []{newPassword});抛异常。
在AD服务器上运行正常,但在加入域的服务器运行就出错。可以断定应该不是程序的问题,但找了很久也没找到解决办法。后来在http://www.highdots.com/forums/asp-net-security/change-password-active-directory-webapplication-700434.html看到一段话:
You may need to experiment with different variations on the dcDNS variable
and you may need to remove the ServerBind flag if you are using a NETBIOS
name. Also, you may need to remove the Sealing flag as well, but be warned
that in order to set or change passwords, some sort of encrypted channel
(SSL or Kerberos) must be available.
突然想到犯了一个低级错误!没有把DNS设置正确!!因为测试AD服务器也是DNS服务器,所以需要把AD服务器的地址配到本机的DNS中。配置后运行成功!
posted on 2006-01-07 12:08 饮酒买醉 阅读(1331) 评论(2)  编辑 收藏

评论

#1楼  2007-01-10 13:28 qu [未注册用户]
我想请问下您:
在 .net下实现一个用户验证的功能,现在老是出错,不知道是不是我LDAP连接字符串的问题,我的LDAP字符串是这样的,LDAP://jieludc.jielu.com.cn/cn=jielu,DC=jielu,DC=com,DC=cn
做活动目录服务器的是jieludc.jielu.com.cn,活动目录有一个组是jielu,里面有我要验证的用户,基本都在里面,ip地址是192.168.20.165 ,和我的dns地址是一样的。现在就是成功不了,出现操作错误,设定DirectoryEntry(results.Path,ADUser,ADPassword,AuthenticationTypes.Secure);还会出现登陆失败,未知的用户名和密码。出错的地方是这句 :SearchResult resEnt in mySearcher.FindAll())。 我不知道我的电脑,也就是运行的电脑在不在域jielu.com.cn中,怎么看。


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.DirectoryServices;

namespace AdLogin
{
/// <summary>
/// test 的摘要说明。
/// </summary>
public class test : System.Web.UI.Page
{


static void Main(string[] args)

{

//

// TODO: Add code to start application here

//

GetAllOU();

Console.ReadLine();

}



//获取目录中需要的组织单元(OU)

public static void GetAllOU()

{

DirectoryEntry entry = new DirectoryEntry("LDAP://jieludc.jielu.com.cn/DC=jielu,DC=com,DC=cn");



DirectorySearcher mySearcher = new DirectorySearcher(entry);



mySearcher.Filter = ("(objectClass=organizationalUnit)");



foreach(SearchResult resEnt in mySearcher.FindAll())

{

Console.Write(resEnt.GetDirectoryEntry().Name.ToString());



//Console.WriteLine("\t"resEnt.GetDirectoryEntry().Name.ToString());

}//end foreach

}//end GetAllOU



private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面


GetAllOU();

Console.ReadLine();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


  回复  引用    

#2楼  2008-07-27 08:11 mhgj [未注册用户]
ngfuhjfyjk564149849gkxhjdywuc btmvhfmj !@##$%$%^^&*&()_++)((*&^%$#@@!!!~~~?><:"""}}{{LLK::>?><MHGFDEWWWSDDFTRE!!@##$%%^%^&~&***(*(((~~~~~~~~~~~~
  回复  引用    


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交