Sunday, December 18, 2016

I am sure I am not alone in scratching my head when trying to figure out why an ASP.NET Core 1.0 web app deployed to Azure crashes and does not work. That happened to me earlier today when I attempted to deploy an ASP.NET Core 1.0 web app that uses the SQLite database to Azure. The error message I received (Oops. 500 Internal Server Error | An error occurred while starting the application) was cryptic and not too helpful – see below:

This is the generic error that is displayed when web apps have their environment variable set to production or staging.

This bears the question – how does one set the environment variable in Azure App Services to a setting that sheds some light on what the problem is? Well, Here’s what I determined:
The name of the environment variable key that your ASP.NET Core 1.0 app uses can be determined by looking at your project’s Debug properties in Visual Studio 2015:

Alternatively, you can peek into Properties/launchSettings.json to see the values for the environment variable in question:

This means that the environment variable that controls detailed error messages is ASPNETCORE_ENVIRONMENT. Ideally, the three common values for this variable are Development, Staging and Production.

My next thought is -, how do I set the ASPNETCORE_ENVIRONMENT environment variable on Azure App Services. It turned out quite easy to do.

1) Login to your Azure subscription then click on “App Services” on the left-side.

2) Next, click on your web application. In my case it is SQLiteWeb, as shown below:

3) On the next blade, click on “Application Settings”:

4) On the next blade, scroll further down until you find the “App Settings” section. Add key=ASPNETCORE_ENVIRONMENT and value=Development as shown below:

Don’t forget to click on Save when you are done.

Now refresh the page that had a cryptic error and, voila, you can see a more meaningful error message:

Even though the error message looks ugly, at least I have something to work on.
BTW, I was able to solve the error by adding the following statement at the bottom of the Configure() method in Startup.cs: