473,498 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to save changes to a web.config section?

How can an application change settings in the web.config file? I need to
allow users to configure SMTP email settings with functionality similar to
that provided developers by the ASP.NET Web Site Administration Tool. I
believe that I can get the settings using ConfigurationManager.GetSection,
but how can I save changes? If I do find a way to save changes, how can I
get IIS to read the file again so that the changes become immediately
available to the web site?

Thanks,

Keith
Mar 26 '06 #1
4 2750
Hi Keith,

You're in luck because ASP.NET 2.0's Web Admin application does all this and
the source code is included. Take a look here:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP. NETWebAdminFiles\AppConfig

Also, check out the Save method here:

http://msdn2.microsoft.com/en-us/lib...ve(VS.80).aspx

Ken
Microsoft MVP [ASP.NET]
public void SaveConfig(Configuration config) {
RemotingManager.ShutdownTargetApplication();
config.NamespaceDeclared = true;

// check if session expired
if (String.IsNullOrEmpty(ApplicationPath) ||
String.IsNullOrEmpty((string)Session[APP_PHYSICAL_PATH])) {
Server.Transfer("~/home2.aspx");
}

config.Save(ConfigurationSaveMode.Minimal);
}

"keithb" <kb******@dslextreme.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
How can an application change settings in the web.config file? I need to
allow users to configure SMTP email settings with functionality similar to
that provided developers by the ASP.NET Web Site Administration Tool. I
believe that I can get the settings using ConfigurationManager.GetSection,
but how can I save changes? If I do find a way to save changes, how can I
get IIS to read the file again so that the changes become immediately
available to the web site?

Thanks,

Keith

Mar 26 '06 #2
As for the second question, IIS resets the application as soon as there's a
change to the web.config.

Ken

"keithb" <kb******@dslextreme.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
How can an application change settings in the web.config file? I need to
allow users to configure SMTP email settings with functionality similar to
that provided developers by the ASP.NET Web Site Administration Tool. I
believe that I can get the settings using ConfigurationManager.GetSection,
but how can I save changes? If I do find a way to save changes, how can I
get IIS to read the file again so that the changes become immediately
available to the web site?

Thanks,

Keith

Mar 26 '06 #3
On Sat, 25 Mar 2006 20:16:40 -0800, keithb wrote:
How can an application change settings in the web.config file?


There's lots of ways, such as simply reading and writing your changes via
file classes, to reading the file into a XMLDom object, making changes, and
saving it again.

However, you should be VERY careful about this, since changing the
web.config file will cause any currently running application (including the
one you're making the changes in) to reset, losing things like session
variables, authentication, the currently state, etc.. Basically, you will
dump the user out of the website entirely, as well as every other user
currently on the site.

If that's not what you want, then you might need to look at other ways of
storing your data that needs changing.
Mar 26 '06 #4
If you want your changes to be immediately available after being written
without having the web application restart on you, then you'll need to wite
them either to an xml file or preferably to a database.

You can have a method in your configuration class's code that automatically
re-reads the data from the database (or file) whenever a change is made.

IIS doesn't read web.config files - the ASP.NET runtime does.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"keithb" wrote:
How can an application change settings in the web.config file? I need to
allow users to configure SMTP email settings with functionality similar to
that provided developers by the ASP.NET Web Site Administration Tool. I
believe that I can get the settings using ConfigurationManager.GetSection,
but how can I save changes? If I do find a way to save changes, how can I
get IIS to read the file again so that the changes become immediately
available to the web site?

Thanks,

Keith

Mar 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3808
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
5
6703
by: Sam Carleton | last post by:
It is my understanding that in .Net the registry is not the prefered place to save application settings. What has Microsoft put in place to replace it? I thought it was the .config file, but I...
3
1886
by: Robert | last post by:
I have an application with custom configuration sections in it's app.config file. Here's a shortened excerpt: <monitors> <monitor...
8
1567
by: Shimon Sim | last post by:
Hi I converted my existing ASP.NET project to VS.NET 2005. Build gives me some warnings about config file. I have custom section definition in web.config. Were there any changes in this for...
1
15472
by: Shannon Richards | last post by:
Hello All: I have implemented a custom configuration section in my app.config file as follows: <configSections> <section name="AdminUIConfig" type="TestMgr.UIConfigSection,TestMgr"/>...
4
3028
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I have referenced a separate config file in my application using the following syntax in web.config: <galleryServerPro configSource="config\galleryserverpro.config"/> There are several admin...
6
1695
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I have configuration data for a web application stored in a file galleryserverpro.config located in a config folder off the root application. Web.config references this file like this:...
0
2602
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi, thanks, mister The code string rutaConfig = tbRutaConfigServicioBase.Text; '// Map to the application configuration file. ExeConfigurationFileMap configFile = New...
0
1624
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi misters, I have an app.config (UTF-8 format file). I create an application winforms for changes and save configuration programatically. When I save changes the format file changes to ANSI ...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.