Hello CS,
Thanks for your reply and the further information.
I've also performed some further test on my local working environment. Here
is the further info I've got:
1. The code works identically on windows XP and windows server 2003. I've
tried the same application code (that modify the web.config file by
SetRawXml ) and as long as the worker process identtiy has sufficient NTFS
file access permission, and application is running under "Full" trust
level(ASP.NET trust level), it can work correctly.
2. As for the <appSettings file="MyFile.config"case, this does be a
problem here. the "file" attribute is .net 1.x feature and it is specific
to <appSettingsto separate the section into an external file. However,
in .net framework 2.0, it has provide a new "configSource" setting that can
be applied to all configuration sections.
#appSettings Element (General Settings Schema)
http://msdn2.microsoft.com/en-us/library/ms228154.aspx
here is the description picked up from the above reference:
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>
Note In the .NET Framework version 2.0, you can now include configuration
settings in a separate file for all configuration elements that support the
configSource attribute. However, when you use the configSource attribute,
you must move the entire section to the separate file because there is no
merging of element settings. There is a one-time write to the Web.config
file when using the configSource attribute. This causes the application to
restart, but subsequent updates to the section are written directly to the
separate file and do not cause subsequent application restarts. For more
information, see ConfigSource.
<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>
So in your web.config, you can change to use the "configSource" attribute
to specify a separate source. e.g.
======in web.config==========
<configuration>
<appSettings configSource="AppSettings.xml">
.............
==========
====in AppSettings.xml==========
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
</appSettings>
===========
thus, the SetRawXml code works correctly(the external AppSettings.xml file
is updated).
test code is quite straight as below:
=========code===============
protected void btnSet_Click(object sender, EventArgs e)
{
Configuration config =
WebConfigurationManager.OpenWebConfiguration(Reque st.ApplicationPath);
AppSettingsSection appset = config.GetSection("appSettings") as
AppSettingsSection;
string rawXML =
"<appSettings<add key=\"key1\" value=\"value1\" /><add
key=\"key2\" value=\"value2\" /><add key=\"key3\" value=\"value3\"
/></appSettings>";
appset.SectionInformation.SetRawXml(rawXML);
config.Save();
}
=============================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.