使用asp.net通信Active Directory用户

时间:2013-02-26 08:21:14

标签: asp.net active-directory forms-authentication

我在我的机器上安装了VM播放器并在里面安装了windows 2008标准核心。同样通过命令提示符为特定用户添加了用户和组,如下所示, 创建用户

dsadd user "cn=username,cn=users,dc=myname,dc=ca" -pwd password -disabled no
creating group
dsadd group "cn=groupname,cn=users,dc=myname,dc=ca"
Also added user to the existing group as below,
dsmod group "cn=groupname,cn=users,dc=myname,dc=ca" -addmbr "cn=username,cn=users,dc=myname,dc=ca"

现在我通过我的本地机器上的asp.net应用程序连接这些用户,如下所示, Web.config设置

<authentication mode="Forms">
      <forms loginUrl="logon.aspx" name="adAuthCookie" timeout="10" path="/"/>
    </authentication>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>

身份验证脚本

void Login_Click(object sender, EventArgs e)
    {
        string adPath = "LDAP://domainaddress:389/DC=somename,DC=m"; //Path to your LDAP directory server
      LdapAuthentication adAuth = new LdapAuthentication(adPath);
      try
      {


        if(true == adAuth.IsAuthenticated(txtDomain.Text, txtUsername.Text, txtPassword.Text))
        {
            FormsAuthentication.SetAuthCookie(txtUsername.Text.Trim(), false);

            string groups = adAuth.GetGroups();

         //Create the ticket, and add the groups.
         bool isCookiePersistent = chkPersist.Checked;
         FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
           txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);
---------
-------
}

我在字符串组中获得异常= adAuth.GetGroups();如下 “验证错误。获取组时出错。用户名不正确或密码错误。”

如果我犯了一些错误,请告诉我或者请让我知道我是如何找到有关用户群的。

此致 桑杰塔

0 个答案:

没有答案