views:

143

answers:

1

I need to programatically add or modify the following section in an asp.net web.config file:

<configuration>
  <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
  </system.web>
</configuration>

I could manipulate the file at the XML level, but I prefer to use the configuration API whenever possible. I found ProtocolElement and ProtocolElementCollection classes, both in the System.Web.Services.Configuration namespace and in the System.Web.Services assembly, but after much googling I can't find any usage examples. I have the system.web.extensions/scripting/webServices sectionGroup defined in the configSections element - is that sufficient, or do I need to add a config section under that?

Any help manipulating this would be appreciated. We're currently using ASP.NET 2.0.

A: 

You should go with WebConfigurationManager and ConfigurationManager classes.

You can also take a look into this question: Changing values in Web.config with a Batch file or in .NET code

Rubens Farias
Thanks for the suggestion; however, I'm already using ConfigurationManager and WebConfigurationManager. Updating "the basics" (i.e. app settings, connection strings, etc.) is easy; it's the more esoteric parts of a web.config file (system.web, etc.) that is the challenge. I will probably go ahead and do this via XML.
glaxaco