title: HttpWebResponse.StatusCode isn't trapping 500 Errors
body: <p><strong>My Question:</strong>
  Does a HttpWebResponse.StatusCode detect Asp.Net errors? Mainly a yellow screen of death?</p>
  
  <p><strong>Some Background:</strong>
  I am working on a simple c# console app that will test servers and services to make sure they are still functioning properly. I assumed since the HttpStatusCodes are enumerated  with OK, Moved, InteralServerError, etc... that I could simply do the following.</p>
  
  <pre><code>WebRequest request = WebRequest.Create(url);
  request.Timeout = 10000;
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  
  if (response == null || response.StatusCode != HttpStatusCode.OK)
  {
     // SERVER IS OK
     return false;
  }
  else
  {
     // SERVER HAS SOME PROBLEMS
     return true;
  }
  </code></pre>
  
  <p>I found out this morning however that this doesn't work. An ASP.Net application crashed showing a Yellow Screen Of Death and my application didn't seem to mind because the response.StatusCode equaled HttpStatusCode.OK.</p>
  
  <p>What am I missing?</p>
  
  <p>Thanks
  // lance</p>
  
  <p><strong>Update</strong>
  Thanks to Jon this seems to be working.</p>
  
  <pre><code> HttpWebResponse response;
   try
   {
     response = (HttpWebResponse)request.GetResponse();
   }
   catch (WebException webexp)
   {
     response = (HttpWebResponse)webexp.Response;
   }
  </code></pre>