如何解决如何确定是否在web.config中编译debug =“ true”
|| 我在这里为应该简单的东西画了一个空白。 我正在尝试做类似的事情: <my:control runat=\"server\" id=\"myid\" Visible=\"<%= (is compilation debug mode?) %>\" />
解决方法
这应该使您在“ 2”部分组中的“ 1”元素:
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 ;
简单!
, HttpContext.IsDebuggingEnabled
属性:
using System.Web;
if (HttpContext.Current.IsDebuggingEnabled) { /* ... */ }
从文档中:
获取一个值,该值指示当前的HTTP请求是否处于调试模式[…]
true
如果请求处于调试模式;否则,false
。
, <my:control runat=\"server\" id=\"myid\" Visible=\"<%= HttpContext.Current.IsDebuggingEnabled %>\" />
请参阅http://msdn.microsoft.com/zh-cn/library/system.web.httpcontext.isdebuggingenabled%28v=vs.90%29.aspx
要么
http://www.west-wind.com/weblog/posts/2007/Jan/19/Detecting-ASPNET-Debug-mode,下面提供了卓有成效的反馈。
, 我敢打赌,您可以使用
#if DEBUG
#endif
ASPX页中的少量代码,而不是后台代码(这是单独的编译)。
就像是:
<script runat=\"server\" language=\"C#\">
protected Page_Load() {
#if DEBUG
myid.Visible = true;
#else
myid.Visible = false;
#endif
}
</script>
或者,您可以使用ConfigurationManager
或XElement
并实际上从代码中解析web.config并找到属性。
例如:
var xml = XElement.Load(\"path-to-web.config\");
bool isDebug = (bool)xml.Descendants(\"compilation\").Attribute(\"debug\");
, 在您的代码中,可以使用IF DEBUG预处理程序指令设置可见性属性:
http://msdn.microsoft.com/zh-CN/library/4y6tbswk.aspx
Phil Haack的精彩文章对此:
http://haacked.com/archive/2007/09/16/conditional-compilation-constants-and-asp.net.aspx#51205
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。