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:
context.Database.Migrate();
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
SchoolContext context)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
context.Database.Migrate();
DummyData.Initialize(context);
}
References:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments
http://druss.co/2016/01/asp-net-core-1-0-automatic-migrations-entity-framework-7-ef-core-1-0/
No comments:
Post a Comment