title: Web API : The remote server returned an error. (500) Internal Server Error. Only when online and not in Local Machine
body: <p>Here's the issue. I am using ASP.NET Web API integration with my project and I am storing the request URLs in the <code>web.config</code>. In my code, I use these URL to fire requests to the Web API and send and receive the data. The URLs are working fine, that I can assure you. The problem here is with this single URL. </p>
  
  <p>Its working when I run both projects on local machine and the flow of data is proper. But when I test run it online after hosting, the same service fails to send me data. Instead, I receive the following exception in the catch block :</p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Internal Server Error.</p>
  </blockquote>
  
  <p>I have already confirmed the following to be true and correct :</p>
  
  <ol>
  <li>The connection strings in both projects.</li>
  <li>No spelling mistakes.</li>
  <li>No incorrect URL.</li>
  <li>When debugging on local, it shows no error and proceeds successfully.</li>
  <li><strong>Perfectly working on local and receiving proper data, only not working online.</strong></li>
  </ol>
  
  <p>I also tried re-hosting. But still the same. Not sure what could be the issue here.</p>
  
  <p>Here is the controller method code :</p>
  
  <pre><code>using (var client = new WebClient())
  {
     Model serviceModel = new Model();
     serviceModel.Number = Num;
     serviceModel.type = "getalldetails";
     client.Headers[HttpRequestHeader.ContentType] = "application/json";
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     var result = client.UploadData(System.Web.Configuration.WebConfigurationManager.AppSettings["GetDetails"], Encoding.UTF8.GetBytes(serializer.Serialize(serviceModel)));//this is the exception point
  }
  </code></pre>
  
  <p>This is the <code>web.config</code> URL:</p>
  
  <pre><code>&lt;add key="GetDetails" value="http://hostname/api/controller/GetDetails" /&gt;
  </code></pre>
  
  <p>Also, I have error logs setup in the Web API side incase of a bad request or something like that, but no new record is inserted in this case. So this is leaving me confused so as to where the issue is.</p>
  
  <p>This is what the exception is :</p>
  
  <blockquote>
    <p>System.Net.WebException was caught   HResult=-2146233079   Message=The
    remote server returned an error: (500) Internal Server Error.<br>
    Source=System   StackTrace:
           at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest&amp; request)
           at System.Net.WebClient.UploadData(Uri address, String method, Byte[] data)
           at System.Net.WebClient.UploadData(String address, Byte[] data)</p>
  </blockquote>