Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET, what determines the value of HostingEnvironment.IsDevelopmentEnvironment?

Tags:

asp.net

The MSDN documentation does not explain how, when or why this value is set to true.

Setting <configuration debug="false" /> in web.config does not set the property to false, nor does setting <deployment retail="true" /> in machine.config.

I'm running the test website from Visual Studio 2012 on IIS Express, I do not have IIS 'proper' installed.

Edit: After reviewing Oscar's answer and doing some more research, it seems that setting <deployment retail="true" /> should override, so I probably didn't set it in the right framework's machine.config when I asked this question.

like image 810
Michiel van Oosterhout Avatar asked Aug 08 '13 20:08

Michiel van Oosterhout


People also ask

How does. NET Core determine environment?

To determine the runtime environment, ASP.NET Core reads from the following environment variables: DOTNET_ENVIRONMENT. ASPNETCORE_ENVIRONMENT when ConfigureWebHostDefaults is called. The default ASP.NET Core web app templates call ConfigureWebHostDefaults .

How to set ASPNETCORE_ENVIRONMENT variable?

To set the ASPNETCORE_ENVIRONMENT environment variable in Windows: Command line - setx ASPNETCORE_ENVIRONMENT "Development" PowerShell - $Env:ASPNETCORE_ENVIRONMENT = "Development"

What are environment variables in ASP.NET Core?

Environment Variables are one of the sources from which ASP.NET Core reads the configuration values. In this tutorial, let us learn how to set Environment Variables in Windows, Mac, Linux, IIS Server, Visual Studio, Visual Studio Code & dotnet run. We also learn how to read them in ASP.NET core.


1 Answers

The decompiled code of this property is as follows:

public static bool IsDevelopmentEnvironment
{
    get
    {
        return ((AppDomain.CurrentDomain.GetData(".devEnvironment") as bool?) == true);
    }
}

But I couldn't fin where this value is set.. :-(

like image 138
Oscar Avatar answered Sep 19 '22 17:09

Oscar