我有一个ASP.NET 3.5 Web应用程序。对于应用程序:
尽管如此,以下代码:
#if ( _DEBUG )
const bool DebugMode = true;
#else
const bool DebugMode = false;
#endif
string strSettings = string.Concat("(DebugMode: ", DebugMode, ")");
将“DebugMode:False”放入结果字符串中。同时我无法在调试模式下使用VisualStudio连接到应用程序...
问题:
如何才能获得调试模式的真正价值?
答案 0 :(得分:1)
您是否将网站编译为Web应用程序?
Compile Pre-Processor指令的_DEBUG
常量由Visual Studio设置并像这样传递给编译器
csc /define:_DEBUG
但是当你访问网站时,它通常不是由Visual Studio编译的,而是asp_net编译器,它只查看编译部分的debug-attribute。您可以使用
在运行时检查此属性的值HttpContext.Current.IsDebuggingEnabled
如果你真的需要在你的网页中定义符号,你可以通过在web.config中指定它来传递/定义编译器的参数
<configuration>
<system.web>
<compilation debug="true">
<compilers>
<compiler language="C#;Csharp" compilerOptions="d:_DEBUG"/>
</compilers>
</compilation>
</system.web>
</configuration>
答案 1 :(得分:1)
这是C#吗?常量为DEBUG
,而不是_DEBUG
。