System.Net.WebException HTTP status code
Is there an easy way to get the HTTP status code from a System.Net.WebException ? Maybe something like this... try { // ... } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { var response = ex.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); } else { // no http status code available } } else { // no http status code available } } Martin Liversage By using the null-conditional operator ( ?. ) you can get the HTTP status code with a single line of code: HttpStatusCode? status = (ex.Response as