Thursday, February 4, 2010

C# - Change compilation debug value of the configuration file at runtime

Below is a C# code snippet to demonstrate on how to change the compilation-debug value at runtime.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises");
            
CompilationSection compSection = ((CompilationSection)(config.GetSection("system.web/compilation")));
            
compSection.Debug = true;

config.Save();

Please note that there might be times that this section is locked, so it is always helpful to check them first. Below is a revision C# code snippet to show that.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/WebPersonalExercises");
CompilationSection compSection = ((CompilationSection)(config.GetSection("system.web/compilation")));
            
compSection.Debug = true;
            
if (!(compileSection.SectionInformation.IsLocked))
{
     config.Save();
}

No comments:

Post a Comment