Base solution for your next web application
Open Closed

ASPNETCORE_ENVIRONMENT is ignored in AZURE has no effect on 8.9.2 #9677


User avatar
0
compassinformatics17 created

Hi All,

We are deploying our product which is AspNetZero Core & Jquery 8.9.2 to Azure. We have encountered an issue with environment configuration. ASPNETCORE_ENVIRONMENT has been set to Production in Azure and I have verified that it is in effect via Kudu. But AspNetZero is still operating in Development mode and returning full stack traces for any errors. I wonder if there is something that I am missing. We have not made any customisations which should affect this functionality.

The only changes we have made to the dev, prod process is that we only use a single appsettings.json file and our deployment process auto replaces the values in this file dependant on the environment into which we are deploying via DevOps. But to my knowlege this code does not alter or reference ASPNETCORE_ENVIRONMENT in any way. Everything works fine via this setup, but I cannot see why the ASPNETCORE_ENVIRONMENT is being ignored by the project.

AppConfigurations.cs

        private static IConfigurationRoot BuildConfiguration(string path, string environmentName = null, bool addUserSecrets = false)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(path)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            // Disable this, we want to always use appsettings.json for clarity and ease of configuration.
            // appsettings.Production.json and appsettings.Staging.json also removed.
            //if (!environmentName.IsNullOrWhiteSpace())
            //{
            //    builder = builder.AddJsonFile($"appsettings.{environmentName}.json", optional: true);
            //}

            builder = builder.AddEnvironmentVariables();

            if (addUserSecrets)
            {
                builder.AddUserSecrets(typeof(AppConfigurations).GetAssembly());
            }

            var builtConfig = builder.Build();
            new AppAzureKeyVaultConfigurer().Configure(builder, builtConfig);

            return builder.Build();
        }
    }

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    AspNet Zero uses log4net for logging, see https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/Startup/Startup.cs#L164. You can configure it in log4net.config file.

  • User Avatar
    0
    compassinformatics17 created

    Hi,

    Thanks for getting back to me. I understand the log4net config but I'm not sure that is related to my issue. My issue is not so much with configuring logging. The logging works fine. But on our live environment, I want the app to run in production mode. But it is ignoring the ASPNETCORE_ENVIRONMENT variable which is set to Production.

    Even though the environment is production, AspNetZero still prints out full stack traces to the screen on error because it is always running in development mode. Any ideas on how to make the framework obey the ASPNETCORE_ENVIRONMENT variable and run in production mode.

    Is there perhaps some known issue with the ASPNETCORE_ENVIRONMENT variable and the framework in Azure?

    Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Normally this line should add environment variables;

    builder = builder.AddEnvironmentVariables();

    One thing can affect this. Is there a web.config file in the root directory of your published application ? If so, does it contain an environment variable decleration in it ?

    Thanks,

  • User Avatar
    0
    compassinformatics17 created

    Hi, I checked the web.config possibility also based on reports on StackOverflow. The web.config file generated by Core during deployment is there but it contains no reference to any environment variable. Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Does your Application settings on Azure contains ASPNETCORE_ENVIRONMENT variable ? If so, maybe you should contact with Azure about this problem as well.