Best way to tell if in production or development environment in .NET
.net, development-environment, production-environment, vb.net, web-applications
Solution
I use what's called Preprocessor Directives (in C#). In VB it's called Directives only.
I have a helper method like this:
public static bool IsDebug()
{
#if DEBUG
return true;
#else
return false;
#endif
}
Then anywhere in the code one can call this method and during runtime and it'll tell if the code is being run in `Debug` ( development ) or if it's the `Release` version ( production ).
Here's the equivalent #If...Then...#Else Directives in (VB).
Problem
I would like to send email differently on production then the development environment, such as sending emails only to me while testing. I know that I can set an application value in the webconfig file or check the url before sending the emails. I would like to know what is the best practice for doing this or if there is some other option that I don't know about that might be better? Any information on this topic would be greatly appreciated.