Monday, June 29, 2009

Programatically Update Web.config file

public partial class UpdateConfigFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration con = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

//open the web.config file to any location. here is the root.

System.Web.Configuration.CompilationSection cs = (System.Web.Configuration.CompilationSection)con.GetSection("system.web/compilation");

//Get the compilation section of opened file
cs.Debug = false;
AssemblyInfo ai = new AssemblyInfo("Kavs");
cs.Assemblies.Add(ai);

//change the value of debug.

con.Save(ConfigurationSaveMode.Modified);

//save changes.



}
}

No comments:

Post a Comment