Operation returned an invalid status code ‘Forbidden’


Today I was getting the below error while getting secret value.

Operation returned an invalid status code ‘Forbidden’

After some search found that I have added the Web APP to Access Policies but never clicked on Save. Just make sure you have added the application in the Access Policies.

Navigate to Keyvault in Azure –> Open the required Keyvault –> Access Policies and Configure the Policy as below.

Configure form Template : Key, Secret and Certificate Management
Select Principal : Select the Application to which you want to provide access.
Key, Secret and Certificate Permissions : Based on your requirement.

Hope this helps.

Happy Coding


Logging in Azure Web APP


Today I was developing an Web APP and it was giving an error after I host it on Azure. To understand the error I have log the traces. Here is the way that explains that how we can do that.

We can directly use Trace class (System.Diagnostics.Trace) for write the logs. I have written the below piece of the code as a first line in the method.

System.Diagnostics.Trace.WriteLine(“I am getting called…”);

Now navigate to your Azure Account –> The app service where you have deployed the Web APP –> Diagnostics Logs.

You have something called “Application Logging (Filesystem)” and you can switch it on. There are four options available there.

Error – Error, Critical
Warning – Warning, Error, Critical
Information – Info, Warning, Error, Critical
Verbose – Trace, Debug, Info, Warning, Error, Critical (all categories)

I normally prefer Verbose as it gives everything.

Now, browse the URL for hitting the action where you have written the tracing.

Navigate to Advance Tools under you AppService and Click on Go

It opens a new tab as below – Click on Debug console and then CMD.

You will see the below screen, click on LogFiles –> Application, you will see the .txt file. Click on Edit icon to see the logs.

Note : For Application logging, you can turn on the file system option temporarily for debugging purposes. This option turns off automatically in 12 hours

Happy Coding