Search code examples
c#.netenvironment

How to check whether a page is run in production or dev or test in .NET/C#?


How can I check whether the page is run in a production, dev, or test environment in .NET/C#? In PHP I can use var_dump($_SERVER) to check, but somehow I have no idea how to check it in .NET or C#.

I need to find out whether the page is run in production/test/dev to display the correct logo and heading on the page.


Solution

  • You can setup as many configuration as you want, by default, you have Debug and Release.

    You can make different web.config files for different configuration, for example: web.debug.config

    More information: http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

    From code you can use directives to test the configuration, for example:

    #if DEBUG
      bool isDebug = true;
    #else
      bool isDebug = false;
    #endif