As for ASP.NET web application (or WCF service web application), we use web.config file to store those application and runtime specific settings. And whenever the web application starts, it will load the configuration file(web.config) settings into memory
and cache it(this is also the same for desktop .NET applications like winform or WPF apps). Therefore, change app.config/web.config file at runtime is not quite recommended. And for web application, if you programmtically change it at runtime, the application(appdomain)
will be restarted (is this your expected behavior)?
For web.config file manipulation, you can use the Webconfigurationmanager class(see web references below):
In addition, if such kind of modification is only done at deployment time(when deploy the web app to different servers), you can consider using the "configSource" attribute to split your web.config (actually those certain sections in web.config file) into
separate xml files. Thus, you only need to provide a new version of the separate xml file when deploying the application to a new server(where new configuration values like connectionString is required).
gsd
Member
290 Points
81 Posts
dynamically assigning value to serviceContract(namespace)
Apr 06, 2012 12:48 PM|LINK
Is it possible to assign a value from web.config to the namespace of ServiceContract & DataContracts?
I want to install the same service on different servers....for different db connections.
Any idea, please...
Steven Cheng...
Contributor
4199 Points
548 Posts
Microsoft
Moderator
Re: dynamically assigning value to serviceContract(namespace)
Apr 10, 2012 02:31 AM|LINK
Hi gsd,
As for ASP.NET web application (or WCF service web application), we use web.config file to store those application and runtime specific settings. And whenever the web application starts, it will load the configuration file(web.config) settings into memory and cache it(this is also the same for desktop .NET applications like winform or WPF apps). Therefore, change app.config/web.config file at runtime is not quite recommended. And for web application, if you programmtically change it at runtime, the application(appdomain) will be restarted (is this your expected behavior)?
For web.config file manipulation, you can use the Webconfigurationmanager class(see web references below):
#How to: Access ASP.NET Configuration Settings Programmatically
http://msdn.microsoft.com/en-us/library/4c2kcht0.aspx
#Programmatically manipulating web.config in ASP.NET 2.0 and ASP.NET 3.5
http://www.dotnetcurry.com/ShowArticle.aspx?ID=102
In addition, if such kind of modification is only done at deployment time(when deploy the web app to different servers), you can consider using the "configSource" attribute to split your web.config (actually those certain sections in web.config file) into separate xml files. Thus, you only need to provide a new version of the separate xml file when deploying the application to a new server(where new configuration values like connectionString is required).
#Using configSource to split configuration files
http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx
#Manage Web.config from an XML file by using the configSource attribute in ASP.NET 2.0 http://www.codeproject.com/Articles/20817/Manage-Web-config-from-XML-File-by-using-configSou
Feedback to us
Microsoft One Code Framework