code_junkie

Programmatically access the <compilation /> section of a web.config?

Nov 13th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. WebConfigurationManager.GetSection("compilation")// Name of the tag in the file
  2. WebConfigurationManager.GetSection("CompilationSection") // Name of the class that I'd expect would be returned by this method
  3. WebConfigurationManager.GetSection("system.web") // Parent tag of the 'compilation' tag
  4.  
  5. using System.Configuration;
  6. using System.Web.Configuration;
  7.  
  8. CompilationSection configSection =
  9. (CompilationSection) ConfigurationManager.GetSection( "system.web/compilation" );
  10.  
  11. XmlDocument doc = new XmlDocument();
  12. doc.Load(Server.MapPath("~/Web.config"));
  13. doc.SelectSingleNode("/configuration/system.web/compilation/@debug");
  14.  
  15. CompilationSection section =
  16. Configuration.GetSection("system.web/compilation") as CompilationSection;
  17. bool debug = section != null && section.Debug;
  18.  
  19. #if (DEBUG)
  20.  
  21. #endif
Add Comment
Please, Sign In to add comment