all groups > visual studio .net setup > november 2007 >
You're in the

visual studio .net setup

group:

Overwrite settings in Web.config


Overwrite settings in Web.config anuragsji
11/1/2007 4:39:09 AM
visual studio .net setup:
Hello,

I am aware that web.config is read only when application is running.
But during installation using setup msi, there is need to overwrite
some settings in web.config by custom actions of setup project (VS
2005).

I know how to read and overwrite the key value pair in <appSettings>
but not in section
NameValueSectionHandler

The webconfig is as follows :
==========================================================
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MySection"
type="System.Configuration.NameValueSectionHandler,system,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,
Custom=null" />
</configSections>
..............
..............
<MySection>
<add key="Key1" value="value1" />
<add key="Key2" value="value2" />
</ MySection>
</configuration>
==========================================================

The code which I wrote in customInstallerActions is as follows (Able
to read write values in web.config if they are in <appSettings>
==========================================================
DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" +
targetSite);
string friendlySiteName =
entry.Properties["ServerComment"].Value.ToString();

// Open Application's Web.Config
Configuration config =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/"
+ targetVDir, friendlySiteName);

//settings in appSettings
String AppInstURL =
config.AppSettings.Settings["ApplicationURL"].Value;
config.AppSettings.Settings["ApplicationURL"].Value =
applicationInstanceURL;
config.Save();
==========================================================
The variable targetSite, targetVDir are reserved words which
recognized by installer.

Please help me.

Thanks,
Anurag
AddThis Social Bookmark Button