title: 403 when calling API from Azure App Service
body: <p>I have a strange problem. I have a .NET Core App which works fine on local machine and passes unit tests.</p>
  
  <p>Inside the app it basically calls our platform web service:</p>
  
  <pre><code>using( WebClient client = new WebClient() )
  {
      NetworkCredential creds = new NetworkCredential(_userName, _password);
      CredentialCache credCache = new CredentialCache();
      credCache.Add(new System.Uri(_baseUrl), "Basic", creds);
      client.Credentials = credCache;
  
      var url = _baseUrl + "/api/v1/Pricing/Rates";
      client.Headers.Add(HttpRequestHeader.ContentType, "application/json");    
      var request = JsonConvert.SerializeObject(data);
      System.Console.Out.WriteLine(request);      
      var response = client.UploadString(url, request);
      var responseObject = JObject.Parse(response);
      var products = responseObject["PricingProducts"].Children();
  
      var result = new Dictionary&lt;string, double&gt;();
      foreach( var product in products ) 
      {
          result.Add(product.Value&lt;string&gt;("LoanProgramName"), 
                     product.Value&lt;double&gt;("Rate"));
      }
      return result;
  }
  </code></pre>
  
  <p>When I execute this on local machine using dotnet run, everything works fine.  Unit tests work great too.  The logs on the App Service don't tell me much except that I am getting a 403 from the platform web service.</p>
  
  <pre><code>ers.RatesController.Get (AlexaRates) with arguments ((null)) - ModelState is Valid
  2018-02-24 06:37:44.418 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executed action AlexaRates.Controllers.RatesController.Get (AlexaRates) in 201.3483ms
  2018-02-24 06:37:44.447 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HLBRA4B41EO8", Request id "0HLBRA4B41EO8:00000002": An unhandled exception was thrown by the application.
  System.Net.WebException: The remote server returned an error: (403) Forbidden.
     at System.Net.HttpWebRequest.GetResponse()
     at System.Net.WebClient.GetWebResponse(WebRequest request)
     at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream)
     at System.Net.WebClient.UploadBits(WebRequest request, Stream readStream, Byte[] buffer, Int32 chunkSize, Byte[] header, Byte[] footer)
     at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest&amp; request)
     at System.Net.WebClient.UploadString(Uri address, String method, String data)
     at Rates.RetrieveLatest() in D:\home\site\repository\AlexaRates\Rates.cs:line 50
     at AlexaRates.Controllers.RatesController.Get() in D:\home\site\repository\AlexaRates\Controllers\RatesController.cs:line 22
     at lambda_method(Closure , Object , Object[] )
     at Microsoft.Exten
  </code></pre>
  
  <p>Has anyone experienced anything similar?  I see a bunch 403 posts, but they are mostly about people calling a REST API hosted on the service not calling out.</p>