如何确定web.config中的编译debug ="true"

Out*_*per 30 c# asp.net debugging

我在这里画一个空白的东西应该很简单......

我想做的事情如下:

    <my:control runat="server" id="myid" Visible="<%= (is compilation debug mode?) %>" />
Run Code Online (Sandbox Code Playgroud)

Adr*_*zar 55

HttpContext.IsDebuggingEnabled属性:

using System.Web;

if (HttpContext.Current.IsDebuggingEnabled) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

从文档:

true如果请求处于调试模式,则获取一个值,该值指示当前HTTP请求是否处于调试模式[...] ; 否则,false.


Nic*_*rey 49

这应该让你获得节组中的<compilation>元素<system.web>:

using System.Web.Configuration ;

. . .

CompilationSection compilationSection = (CompilationSection)System.Configuration.ConfigurationManager.GetSection(@"system.web/compilation") ;

. . .

// check the DEBUG attribute on the <compilation> element
bool isDebugEnabled = compilationSection.Debug ;
Run Code Online (Sandbox Code Playgroud)

简单!

  • 为什么不用HttpContext.Current.IsDebuggingEnabled? (11认同)
  • @AdrianSalazar在某些情况下,HttpContext可以为null,例如,运行异步后台线程的进程与上下文分开运行. (3认同)
  • @ErgonomicDeveloper好,请参阅问题本身.我们正在渲染一个控件,而不是运行异步代码.这个帖子会有一个HttpContext,所以我不担心. (2认同)