title: Easy, best way to check if WebAPI is available in C# Code Behind
body: <p>What is the best way to check if the WebAPI is available or not? I want to check it in a simple <code>if()</code> statement, is it even possible to keep it relatively simple? if there is a better way to check. like a try/catch. just tell me. Thanks</p>
  
  <p>I want to include the if-statement in my code-behind <code>Page_Load</code> Method. So I can block the site when the API is not available. </p>
  
  <p>I tried this:</p>
  
  <pre><code>try
    {
         WebClient client = new WebClient();
         client.UseDefaultCredentials = true;
  
         string response = client.DownloadString(baseuri + Constants.API_LEHRLING + lehrlingID);
     }
     catch (Exception ex)
     {
          string url = "AccessDenied.aspx";
          Server.Transfer(url, true);
     }
  </code></pre>
  
  <p>I am trying to Download a string from my webapi. my uri is built automatically. if a exception happens, i refer to my Error site. </p>
  
  <p>Any other ideas? this method works, but its not very clean</p>