Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms



Visual 2008 New Features
Dynamically Update Config file in .NET
Cubes & Rollups in MS SQL Server
Creating XML on Runtime
Creating Shared Assemblies
IBM MQ Manager
ASCII Code A Glance
Generate Captcha Code
Creating Strong Password
ASP.NET Page Life Cycle
Colours of RGB


Dynamically Update Config File

There are scenarios where data need to be changed in the web.config at runtime.
Let's take an example, where session states need to be changed in web.config on the bases of options selected by user.

Isn't a good example..?

So the application changes the value of "mode" under SessionState node of web.config and uses the value as InProc or SQLServer, for maintaining the session state.

I know after reading the above dynamics change in web.config file, as per the requiremaent, you would like to see the actual code to make this possible.
Please see the code for changing the config file at the run-time..

void Application_Start(object sender, EventArgs e)
// Code that runs on application startup
Configuration config;
config = WebConfigurationManager.OpenWebConfiguration("~");
SessionStateSection SessionState = config.GetSection("system.web/sessionState") as SessionStateSection;

if (SessionState != null)
SessionState.Mode = System.Web.SessionState.SessionStateMode.InProc;
//SessionState.Mode = (SessionStateSection)"Mode=InProc";

So, similary there can be different cases where we can dynamically change the value of config file.



Download Links

  Download Microsoft Framework

Copyright, does not endorse external sites and is not responsible for their content. For any feedback - please send an email at