Bestcomy.net blog

Coding for funny

导航

利用反射获得WEB应用程序的动态调试编译信息

Posted on 2004-08-12 18:12  bestcomy  阅读(820)  评论(0编辑  收藏  举报

最近看了一下反射,写了个通过反射获得WEB应用程序的动态调试编译信息的例子,如下:

BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            
object obj = HttpContext.Current.GetConfig("system.web/compilation"); 
            Type type 
= obj.GetType();
            Response.Write(type.GetProperty(
"DebuggingEnabled",flags).GetValue(obj,null));

本示例获得WEB应用程序配置信息的<compilation defaultLanguage="c#" debug="true" />节的degug值。
由此类推通过反射可以获得web.config的其它相关信息,这样获得的信息是运行时信息,因此当与machine.config的相关配置节重复时,获得的是准确的运行时配置信息。
注意:此示例基于.net framework 1.1 ,在.net framework 2.0 中可能有变化