我正在使用C#开发一个ASP.NET MVC Web应用程序。我有一组全局变量,例如:
public static class Global
{
public const string RootUrl = "http://url/";
}
我想在发布模式和调试模式下设置不同的值。有人能给出如何实现的建议吗?
我正在使用C#开发一个ASP.NET MVC Web应用程序。我有一组全局变量,例如:
public static class Global
{
public const string RootUrl = "http://url/";
}
您可以使用预处理器指令来为不同的调试/发布值进行设置。
#if DEBUG
public const string RootUrl = "http://url/";
#else
public const string RootUrl = "http://another/";
#endif
web.config
配置来区分环境。看看你的解决方案:
web.config
中使用appSettings
部分:<configuration>
<appSettings>
<add key="GlobalValue1" value="1" />
</appSettings>
</configuration>
我相信应该是以下内容:
#if !DEBUG
// Your code here
#endif