title: How to ignore 401 unauthorized error from webrequest to get website status
body: <p>I am writing an application to check the status of some internal web applications. Some of these applications use Windows authentication. When I use this code to check the status, it throws <code>The remote server returned an error: (401) Unauthorized.</code>. Which is understandable because I haven't provided any credentials to the webiste so I am not authorized.
  <br></p>
  
  <pre><code>WebResponse objResponse = null;
  WebRequest objRequest = HttpWebRequest.Create(website);
  objResponse = objRequest.GetResponse();
  </code></pre>
  
  <p><br>
  Is there a way to ignore the 401 error without doing something like this?
  <br></p>
  
  <pre><code>WebRequest objRequest = HttpWebRequest.Create(website);
  
  try
  {
      objResponse = objRequest.GetResponse();
  }
  catch (WebException ex)
  {
      //Catch and ignore 401 Unauthorized errors because this means the site is up, the app just doesn't have authorization to use it.
      if (!ex.Message.Contains("The remote server returned an error: (401) Unauthorized."))
      {
          throw;
      }                    
  }
  </code></pre>