I'm developing an ASP.NET MVC web application using C#. I have a set a global variables, for example:
public static class Global
{
public const string RootUrl = "http://url/";
}
I want to set them with different values for release and debug mode. Could anyone give a suggestion on how to do this?
You can use preprocessors directives for different debug/release values.
#if DEBUG
public const string RootUrl = "http://url/";
#else
public const string RootUrl = "http://another/";
#endif
Although this is not direct answer, your question seems to be more configuration-related and I recomend to use web.config
configuration for distinct environments. Look at your solution:
Moreover, storing settings in external file is much better than embeding them into application's binaries. What if one of the URL's changes? You will have to recompile and deploy new version of application.
The simplest way is to use appSettings
section in the web.config
:
<configuration>
<appSettings>
<add key="GlobalValue1" value="1" />
</appSettings>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With