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;
}
Yavuz B.
Member
5 Points
17 Posts
Shortest/Fastest way to check if active directory/domain is responding
Feb 01, 2013 09:33 AM|LINK
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
Rion William...
All-Star
27656 Points
4574 Posts
Re: Shortest/Fastest way to check if active directory/domain is responding
Feb 01, 2013 02:10 PM|LINK
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.