title: Unable to connect to Azure Key Vault from Azure Web App
body: <p>I am trying to access Azure Key Vault from my Azure App Service. I followed the steps outlined on this documentation: <a href="https://docs.microsoft.com/en-us/azure/key-vault/managed-identity" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/key-vault/managed-identity</a> (turned on system assigned identity for the app service, updated the access policy of the key vault to include the app with Get,List secret permissions). 
  <br/> <br/> 
  However, when I run the web application, it is not able to get the secret from the key vault and my web service hits the following error: 
  <br/> 
  502 - Web server received an invalid response while acting as a gateway or proxy server.
  There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.
  <br/><br/>
  This is what my code looks like:</p>
  
  <pre><code>AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
  KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
  var secret = keyVaultClient.GetSecretAsync(KeyVaultUrl);
  authenticationKey = secret.Result.Value;
  </code></pre>
  
  <p>The service gets stuck on the secret.Result.Value line. Is there something else I need to do? </p>