locked
Shortest/Fastest way to check if active directory/domain is responding RRS feed

  • Question

  • User2085410294 posted

    Hi,

    i need to get some information about users from the active directory. But before i do that the user must specify a domain name.

    Which is the fastest way to check if the provided domain name is valid and a connection to the ad is possible?

    regards

    yavuz

    Friday, February 1, 2013 5:33 AM

Answers

  • User281315223 posted

    You may want to consider making a quick HttpRequest just using the HEAD method (to avoid pulling all of the content) and checking the Response to see if it was valid : 

    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(yourUrl);
    request.Timeout = 15000; //Allow 15 seconds to process the Request otherwise timeout
    request.Method = "HEAD";
    try
    {
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            return response.StatusCode == HttpStatusCode.OK;
        }
    }
    catch (WebException)
    {
        return false;
    }
    

    as per the C# Wizard Jon Skeet's suggestion.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 10:10 AM