473,657 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

saving web.config file

Anybody has idea how to save value in web.config file during runtime?
ConfigurationSe ttings.AppSetti ngs.Add("test", "test value");

won't work, it will cause and error : the file is read only during rumtime.


Nov 18 '05 #1
1 1577
That is correct and for good reason. When you make a change to the
machine.config/web.config files, it causes your application to restart. Not
too gracfully, I might add. There are a couple of work-arounds though.

A. Use a separate config file aside from web.config to hold runtime values
that might change.
B. Here is some code that will work, but USE IT AT YOUR OWN RISK. I have not
tested it, nor would I on a running asp.net application as it would cause
the application to restart as soon as it can.

using System.IO;
using System.Xml;

private void AddWebConfigVal ue(string name, string val)
{
try
{
//first we need to grab the web.config file.
string webconfig = Server.MapPath( "./web.config");
if(File.GetAttr ibutes(webconfi g) == FileAttributes. ReadOnly)
{
File.SetAttribu tes(webconfig, FileAttributes. Normal);
}

XmlDocument doc = new XmlDocument();
doc.load(webcon fig);
XmlNode node =
doc.DocumentEle ment.SelectSing leNode("configu ration/appSettings");
if(null != node)
{
XmlNode ne = doc.CreateNode( XmlNodeType.Ele ment,"add","");
ne.Attributes["key"] = name;
ne.Attributes["value"] = val;
node.AppendChil d(ne);
}

doc.Save(webcon fig);
File.SetAttribu tes(webconfig, FileAttributes. ReadOnly);
}
catch(Exception ex)
{
//aw crap... ;)
}
}

HTH,
Bill P.

"Blue Man" <bl**********@n ospam.com> wrote in message
news:e6******** ******@TK2MSFTN GP12.phx.gbl...
Anybody has idea how to save value in web.config file during runtime?
ConfigurationSe ttings.AppSetti ngs.Add("test", "test value");

won't work, it will cause and error : the file is read only during rumtime.

Nov 18 '05 #2

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

Similar topics

6
2227
by: Ramesh | last post by:
Hi, We are receiving an error 'The operation has timed out' when our ASP.NET application on Web Server stores large files 10MB+ on the App Server using HTTP PUT. This is a Server to Server communication. This works fine with 4-5 MB files though. Also there is a 15 mb shared bandwidth limitation. how can we throttle/control the transfer rate to see that we are within the bandwidth limits ? Any help is highly appreciated
7
16561
by: Kirk | last post by:
Hello, I am trying to find a VB.NET method that will allow me to save and read an application's settings in a separate file located on any drive, any folder. I have found a couple of methods for doing this, but they are (in my opinion) more complicated than I require. I found a method that uses IsolatedStorageFile and IsolatedStorageFileStream, which works correctly. That is, it stores the settings in XML format to a file located...
11
1425
by: SuperHik | last post by:
Hi, I was wondering how to make a single .exe file, say some kind od clock, and be able to save some settings (alarm for example) into the same file? Basically make code rewrite it self... thanks!
4
6718
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
6
8112
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a picture of themselves to their profile... I admit that I'm a newbie... but this is how I understand this:
2
1677
by: Mufasa | last post by:
Can anybody give me an opinion on which is more efficient - Saving parameters in a database that is on the same machine as the web site or Reading parameters from a .config file ? It seems like the constant opening/closing of the connection would be a congestion spot - plus it would use lots of memory. But when you have the options in a file - is that slow there?
1
1692
by: WebCM | last post by:
We can do it in different ways. Configuration data are sent by POST. Some of them should be parsed before saving to file. Perhaps, I will use var_export(). However, how to do it best? 1. Without a class / function. Fields names have no prefix and are equal to $cfg array's indexes. <input name="option_name" /> In every file of options form (e.g. main options, content options, e-
0
1174
by: jordonkraft | last post by:
Hello, I have been searching the net, MSDN, google groups and can't seem to find anything about what is happening to me. I have developed a application using VB.Net 2.0 and deploy it using ClickOnce over a private network. I use AppSettings.Get("") to retrieve values form my app.config and I use AppSettigns.Settigns("").value = value to set values.
5
3704
by: akshaycjoshi | last post by:
Ok ! I am reading the book Pro ADO.net. The author says that the <exename>.config files can store the connection string for security purposes. Later he says that still the connection string is visible to it's better to encrypt it. He explains that there is a new protectedData section in configuration files specifically for this purpose.
0
8312
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
8732
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
8504
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
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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
6169
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...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.