【问题标题】:Get user photo from Active directory not working at server从 Active Directory 获取用户照片在服务器上不起作用
【发布时间】:2015-01-04 06:12:20
【问题描述】:

我正在开发一个内部网站,该网站直接从 Windows 身份验证中获取用户名,然后在以下功能中从活动目录中获取更多数据,例如用户图像和用户电子邮件等

public Boolean userAuth()
{
    String myUser = Environment.UserName; 
    if (myUser == null)
    {
        return false; 
    }


    DirectoryEntry de = new DirectoryEntry();
    de.Path = "LDAP://mydomain.com";
    DirectorySearcher search = new DirectorySearcher();
    search.Filter = "(SAMAccountName=" + myUser + ")";
    search.PropertiesToLoad.Add("cn");
    search.Filter = "(&(objectClass=user)(objectCategory=person)(sAMAccountName=" +myUser + "))";
    search.PropertiesToLoad.Add("samaccountname");
    search.PropertiesToLoad.Add("thumbnailPhoto");
    search.PropertiesToLoad.Add("Company");
    SearchResult user;
    user = search.FindOne();
    String userName;
    userName = Convert.ToString(user.Properties["sAMAccountName"][0]);
    byte[] bb = (byte[])user.Properties["thumbnailPhoto"][0];
    string imgString = Convert.ToBase64String(bb);
    Session["UserPhoto"] = String.Format("<img width='40' src=\"data:image/Bmp;base64,{0}\">", imgString);
    result = search.FindOne();
    if (null == result)
    {
        return false;
    }

    return true;
}

当我在本地电脑上运行站点时,我的电脑连接到域,它工作正常,但是当我把它放在公司应用程序服务器中时 Environment.UserName 不会返回用户名,所以我使用 System.Web.HttpContext.Current.User.Identity.Name.Replace("mydomain","") 但它会返回那个 user null

我想从 AD 中获取用户照片以在 Intranet 站点中使用。

【问题讨论】:

    标签: asp.net .net c#-4.0 dns active-directory


    【解决方案1】:

    我在 iis application pool advanced settings set process module identity to a user who already in the domain 中找到了答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多