none
.net操作域 RRS feed

  • 问题

  • 各位达人:

    小弟昨天遇到了一个奇怪的问题,当使用.net获取域信息时,在VS中运行可以正常读取域及域用户信息,但是当网站发布后,就无法获取域信息。

    private staticDirectoryEntry GetDirectoryObject()

    {

    DirectoryEntry entry = newDirectoryEntry("LDAP://EMRSN", "adm", "Fengye", AuthenticationTypes.Secure);

    return entry;

    }

    publicstaticDirectoryEntry GetDirectoryEntryByAccount(string sAMAccountName)

    {

    DirectoryEntry de = GetDirectoryObject();

    DirectorySearcher deSearch = newDirectorySearcher(de);

    deSearch.Filter =

    "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + sAMAccountName + "))";

    deSearch.SearchScope =

    SearchScope.Subtree;

    try

    {

    SearchResult result = deSearch.FindOne();

    de =

    newDirectoryEntry(result.Path);

    return de;

    }

    catch

    {

    returnnull;

    }

    }

    publicstring getUsername()

    {

    string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

    string[] info = username.Split(newchar[1] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

    string adname="";

    if (Environment.UserDomainName.Equals("EMRSN"))

    {

    DirectoryEntry de = newDirectoryEntry();

    de = GetDirectoryEntryByAccount(info[1]);

    if (de != null)

    {

    if (de.Properties["distinguishedName"][0].ToString().Contains("Xian-eResource"))

    {

    adname= de.Properties["displayname"][0].ToString();

    }

    else

    {

    adname="";

    }

    }

    else

    {

    adname="";

    }

    }

    return adname;

    }

    高手解救啊,谢谢!

    2012年11月12日 2:06

答案