private HttpStatusCode GetHttpStatusCode(string url) { HttpWebResponse httpWebResponse = null; HttpStatusCode httpStatusCode; var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.AllowAutoRedirect = false; try { httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); httpStatusCode = httpWebResponse.StatusCode; } catch (WebException e) { httpStatusCode = ((HttpWebResponse)e.Response).StatusCode; } if (httpWebResponse != null) httpWebResponse.Close(); return httpStatusCode; }