zoukankan      html  css  js  c++  java
  • Windows身份认证,通过活动目录得到用户信息

     

    //获取到域名

                    string domainName = HttpContext.Current.User.Identity.Name;

                    UserManager manager = new UserManager();

                    EmpInfo empInfo = manager.GetUserInfo(domainName);

    2

    public string GetEmpId(string domainName)

            {

                string id = string.Empty;

     

                if (!string.IsNullOrEmpty(domainName))

                {

                    string[] parts = domainName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);

                    id = parts[parts.Length - 1];

                }

     

                return id;

            }

    3

    DirectoryEntry de = new DirectoryEntry("LDAP://DC=cts,DC=com");

     

                    DirectorySearcher search = new DirectorySearcher(de);

                    search.Filter = string.Format("(sAMAccountName={0})"empId);

     

     

                    SearchResult result = search.FindOne();

     

                    SetUserAdInfo(resultuser);

    4

    private static void SetUserAdInfo(SearchResult searchEmpInfo emp)

            {

                LogManager manager = new LogManager();

                try

                {

                    //manager.AddLog(GetLdapProperty(search, "givenName"));

                    emp.EMP_FIRST_NAME = GetLdapProperty(search"givenName");

                    emp.EMP_LAST_NAME = GetLdapProperty(search"sn");

                    emp.DisplayName = GetLdapProperty(search"displayName");

                    emp.MAIL_ADDRESS = GetLdapProperty(search"mail");

                   

                }

       }

    第二种方法

      string _path = "LDAP://" + ConfigurationSettings.AppSettings["ADServer"];

            public string GetDisplayName(string username)

            {

                DirectoryEntry entry = new DirectoryEntry(_path);

                try

                {

                    DirectorySearcher searcher = new DirectorySearcher(entry);

                    searcher.Filter = string.Format("(SAMAccountName={0})", username);

                    SearchResult result = searcher.FindOne();

                    if (null == result)

                    {

                        return "none";

                    }

                    else

                    {

                        return (string)result.Properties["displayName"][0];

                   }

    }

  • 相关阅读:
    D3使用方法
    CSS3 Media Queries
    前端软件sublime的一些常用快捷键
    如何引入外部图标集及使用方法——以bootstrap图标集为例
    如何引入外部font文字
    纯css3实现 transtion过渡效果
    svn检出项目
    关于a标签自身的click事件所带来的一些影响
    在服务器上建好的组成员如何和建好的TFS团队项目二者联系起来
    在VS上添加TFS团队项目时报错TF218027的完美解决方法
  • 原文地址:https://www.cnblogs.com/Amity/p/2977755.html
Copyright © 2011-2022 走看看