Hi guys!
I have a code:

String Lastlogon(string username, string domain)
        {
            try
            {
                {
                    DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain,domain);
                    DateTime latestLogon = DateTime.MinValue;
                    string servername = null;
                    DomainControllerCollection dcc = DomainController.FindAll(context);
                    foreach (DomainController dc in dcc)
                    {
                        DirectorySearcher ds;
                        using (dc)
                        using (ds = dc.GetDirectorySearcher())
                        {
                            ds.Filter = String.Format("(sAMAccountName={0})",username);
                            ds.PropertiesToLoad.Add("lastLogon");
                            ds.SizeLimit = 1;
                            SearchResult sr = ds.FindOne();
                            if (sr != null)
                            {
                                DateTime lastLogon = DateTime.MinValue;
                                if (sr.Properties.Contains("lastLogon"))
                                {
                                    lastLogon = DateTime.FromFileTime((long)sr.Properties["lastLogon"][0]);
                                }
                                if (DateTime.Compare(lastLogon, latestLogon) > 0)
                                {
                                    latestLogon = lastLogon;
                                    servername = dc.Name;
                                }
                            }
                        }
                    }
                    return latestLogon.ToString();
                }
            }
            catch (Exception)
            {
                err = true;
                return null;
            }
        }

as a domain I provide "woobie.net"
as an user I provide Login "jlennon"

Unfortunately I always receive a message "server not operational"
Anyone knows what can be wrong with that code?

Hmmh..
From what I have read...Everything is ok...
I have checked the DNS server with IPCONFIG..and its correct :/

I have admin rights to extract everything I want...
Only this parameter is problematic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.