首页 > Windows开发 > 详细

get windows auth code

时间:2018-10-23 19:42:04      阅读:173      评论:0      收藏:0      [点我收藏+]
public static WindowsIdentityInfo GetWindowsIdentityInfo(HttpContext context)
        {
            WindowsIdentityInfo info = new WindowsIdentityInfo();
            info.IsAuthenticated = false;
            if (context==null)
            {
                WindowsPrincipal winPrincipal = (WindowsPrincipal)context.User;
                if (winPrincipal != null)
                {
                    info.IsAuthenticated = winPrincipal.Identity.IsAuthenticated;
                    info.UserName = winPrincipal.Identity.Name;
                    if (!string.IsNullOrEmpty(info.UserName))
                    {
                        string[] arr = info.UserName.Split(‘\\‘);
                        if (arr != null && arr.Length >= 2)
                        {
                            info.DisplayName = GetUserFullName(arr[0], arr[1]);
                        }
                    }
                    info.AuthenticationType = winPrincipal.Identity.AuthenticationType;
                }
            }
            return info;
        }

        private static string GetUserFullName(string domain, string userName)
        {
            DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User");
            return (string)userEntry.Properties["fullname"].Value;
        }

  

get windows auth code

原文:https://www.cnblogs.com/yafeili/p/9838116.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!