SteGriff

Blog

Next & Previous

ASP.Net Core app failed to start - Set the environment

You deployed your web app from VS or DevOps to Azure App Services, and you were sure you’d:

Screenshot of publish settings which all match nicely

And yet, when it spins up, you get HTTP Error 500.30 - ASP.NET Core app failed to start:

Screenshot of web browser showing app failed to start error

Remember - or let me tell you - that publishing with the right settings in .Net Core/Modern doesn’t transform the config in the same way that it did in ol’ .Net Framework.

When you used to publish with a build configuration like “LIVE” it would use the transform from web.LIVE.config to modify the web.config, which was then used by the app.

In the .Net Core model, with appsettings.json, all the child settings files, like appsettings.LIVE.json are deployed to the server, but the right one is selected at runtime.

To select the config, ASP.Net Core reads from an environment variable, either:

(Simplified from Use multiple environments in ASP.NET Core)

Set the environment in Azure Portal

Screenshot of setting the ASP Net Core Environment variable in the Azure Portal

You can set this in Azure Portal:

Set the environment in web.config at publish time

You can use dotnet publish to set the Environment variable in web.config, though I’ve not tried this.

Check out Aden’s blog post, “Set ASPNETCORE_ENVIRONMENT in web.config using .NET Core CLI”.

Relevant bit, in case his blog goes away:

Pass the EnvironmentName parameter to dotnet publish:

dotnet publish --configuration UAT /p:EnvironmentName=UAT

This will generate a web.config file, or modify it if you already have one, to include the ASPNETCORE_ENVIRONMENT, e.g.:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <aspNetCore>
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="UAT" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

Conclusion

Once you’ve set the ASPNETCORE_ENVIRONMENT, you can be confident that your site is picking up the right config, and hopefully it comes alive. If not, you have a different problem!

Enjoy 🥅😪