Friday, December 8, 2006

C# Write content to web.config TRACE SECTION

//parameter for OpenWebConfiguration
//null == uses web.config at
// C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG


Configuration root = WebConfigurationManager.OpenWebConfiguration("~/");

System.Web.Configuration.TraceSection traceSection =
(TraceSection)root.GetSection("system.web/trace");

traceSection.Enabled = true;
traceSection.LocalOnly = true;
traceSection.PageOutput = false;
traceSection.RequestLimit = 10;
traceSection.MostRecent = true;
traceSection.TraceMode = TraceDisplayMode.SortByCategory;

System.Web.Configuration.HttpCookiesSection cookie =
(HttpCookiesSection)root.GetSection("system.web/httpCookies");
cookie.HttpOnlyCookies = true;

//update file with TRACE and COOKIES
root.Save(ConfigurationSaveMode.Full);