473,836 Members | 1,277 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 ConfigurationMa nager.GetSectio n,
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 2767
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\Micr osoft.NET\Frame work\v2.0.50727 \ASP.NETWebAdmi nFiles\AppConfi g

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(Conf iguration config) {
RemotingManager .ShutdownTarget Application();
config.Namespac eDeclared = true;

// check if session expired
if (String.IsNullO rEmpty(Applicat ionPath) ||
String.IsNullOr Empty((string)S ession[APP_PHYSICAL_PA TH])) {
Server.Transfer ("~/home2.aspx");
}

config.Save(Con figurationSaveM ode.Minimal);
}

"keithb" <kb******@dslex treme.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 ConfigurationMa nager.GetSectio n,
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******@dslex treme.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 ConfigurationMa nager.GetSectio n,
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 ConfigurationMa nager.GetSectio n,
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
3832
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* access config files. This is version 3, which is a big overhaul. It extends ConfigObj to reading config files with sections and various other simplifications. I find ConfigObj extremely easy to use and use it for reading config files and data...
5
6734
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 am unable to figure out how to write to the file. Sam
3
1944
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 type="SystemMonitor.Monitors.NetworkAvailabilityMonitor,SystemMonitor"> <notifiers> <notifier type="SystemMonitor.Notifiers.MessageBoxNotifier,SystemMonitor" />
8
1592
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 ASP.NET 2.0. Where can I see what was change and how I can migrate? Thank you Shimon.
1
15524
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"/> </configSections> <AdminUIConfig name="Admin" caption="Administrator" captionLC="administrator">
4
3043
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 pages that modify one or more settings in this file, and I need the application to automatically recycle when this happens so that it loads the new values. Under IIS7 (Vista) this works fine. However, IIS6 does not recycle the app when this file...
6
1711
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: <galleryServerPro configSource="config\galleryserverpro.config"/> I built a custom configuration settings class (inherited from ConfigurationSection) to access this data and it works great in Full Trust. However, in Medium Trust I get a SecurityException...
0
2625
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 ExeConfigurationFileMap();
0
1647
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 :( but I need format file UTF-8, and too when I open app.config and changed it, Visual Studio save it like UTF-8. Any suggestions or comments, please ? I need help about it
0
9814
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9666
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10543
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10585
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9368
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7786
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6976
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5819
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.