Search code examples
asp.net.netasp.net-development-serv

how to know programmatically if my app is running under "ASP.NET Development Server"?


I have some default values for testing my code, but for security reasons those values must be set just when my app is running under the ASP.NET Development Server not in Production. How can I programmatically determine where my app is running?


Solution

  • A technique is to add a property to your config which can be set using a coding transform file. In your web.config, "DEV" might be true. In your production transform file, your "DEV" might by false. With this technique, you can even have a value to determine if you are in Staging, Testing, Pre-Production for example. This is a technique used for changing connection strings as well.

    A transform file is used to change various values in your config depending on your deployment.

    Here's more reading: How to: Transform Web.config When Deploying a Web Application Project