2

我在我的机器上安装了 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(); 如下“身份验证错误。获取组时出错。用户名不正确或密码错误。”

如果我犯了一些错误,请告诉我,或者请告诉我如何找到相关用户组。

问候桑吉塔

4

0 回答 0