在一个AD域里面,ASP.NET,如何取得客户机域帐号?即IIS服务器是一个域成员,其他PC机都是加入域的方式.

解决方案 »

  1.   

    using System.DirectoryServices;
    using System.Collections; public bool IsAuthenticated(string domain,string username,string pwd)
    {
    string domainAndUsername=domain+@"\"+username;
    DirectoryEntry entry=new DirectoryEntry(_path,domainAndUsername,pwd);
    try
    {
    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;
    }
    _path=result.Path;
    _filterAttribute=(String)result.Properties["cn"][0];
    }
    catch(Exception ex)
    {
    System.Console.Write(ex.Message);
    return false;
    }
    return true; }