如何在asp.net中使用LDAP# [英] How to use LDAP in asp.net c#

查看:170
本文介绍了如何在asp.net中使用LDAP#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中使用LDAP#?



< appsettings>

< add key =DirectoryPathvalue =LDAP:// XXXXXXXX,XXXXXX,XXXXXX>

< add key =DirectoryDomainvalue =YY>







我从谷歌那里得到这个代码,请你能帮帮我,是什么



DirectoryPath

DirectoryDomain



value =LDAP:// XXXXXXXX,XXXXXX,XXXXXX

value = YY



谢谢。

How to use LDAP in asp.net c# ?

<appsettings>
<add key="DirectoryPath" value="LDAP://XXXXXXXX,XXXXXX,XXXXXX">
<add key="DirectoryDomain" value="YY">



I got this code from google, please can you help me, what is

DirectoryPath
DirectoryDomain

value="LDAP://XXXXXXXX,XXXXXX,XXXXXX"
value="YY"

Thanks.

推荐答案

试试这些链接 -

< a href =https://msdn.microsoft.com/en-IN/library/ms180890%28v=vs.80%29.aspx>来自ASP .NET的Active Directory身份验证 [ ^ ]

登录认证n使用LDAP(Active Directory)进行ASP.NET应用程序的文章和示例。 [ ^ ]
Try these links -
Active Directory Authentication from ASP .NET[^]
Login authentication using LDAP (Active Directory) for ASP.NET applications article and examples.[^]






请注意参考资料



来自ASP .NET的Active Directory身份验证 [ ^ ]


首先需要System.DirectoryServices命名空间,检查用户是否是在LDAP(活动目录)中进行身份验证,然后您可以使用以下代码段

First you need to System.DirectoryServices namespace, to check if the user is Authenticated in LDAP (active directory) then you can use below snippet
public bool IsAuthenticated(string domain, string username, string pwd)
  {
    string domainAndUsername = domain + @"\" + username;
    DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

    try
    {
      //Bind to the native AdsObject to force authentication.
      object obj = entry.NativeObject;

      DirectorySearcher search = new DirectorySearcher(entry);

      search.Filter = "(SAMAccountName=" + username + ")";
      search.PropertiesToLoad.Add("cn");
      SearchResult result = search.FindOne();

      if(null == result)
      {
        return false;
      }

      //Update the new path to the user in the directory.
      _path = result.Path;
      _filterAttribute = (string)result.Properties["cn"][0];
    }
    catch (Exception ex)
    {
      throw new Exception("Error authenticating user. " + ex.Message);
    }

    return true;
  }


这篇关于如何在asp.net中使用LDAP#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆