I have created a method in windows services in asp.net application.
public static bool Test(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "HEAD";
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
resp.Close();
return true;
}
catch
{
return false;
}
}
JurisdictionBL jbl = new JurisdictionBL(0);
DataSet jds = new DataSet();
jbl.FetchAll(jds);
foreach (DataTable table in jds.Tables)
{
foreach (DataRow dr in table.Rows)
{
var jId = dr["Jurisdiction"].ToString();
var jurl = dr["URL"].ToString();
if (Test(jurl))
{
jbl.IsValidUrlTrue(Convert.ToInt32(jId));
}
else
{
jbl.IsValidUrlFalse(Convert.ToInt32(jId));
}
}
}
The whole application does not work. It gets stuck. Basically I have a field "IsValidURL" in table tbJurisdiction and a field URL which needs to be constantly checked whether they are working or not. If they are not working then IsValidURL should become false. Also It is not checking any url properly. If any url is not valid it still display isvalidURL Feild true
Please Help me !!!