views:

197

answers:

2

Are there any .NET APis that can read/update the system.webServer node in web.config? I know I can do it via reading/parsing the web.config file as xml but that's awkward.

To read/update the system.web node in .NET 2 I can use:

HttpModulesSection httpModulesSection = (HttpModulesSection)configuration.GetSection("system.web/httpModules");

But is there any API based way of accessing system.web/modules using .NET 2?

I have to reference the .NET 2 version of system.web.configuration because I don't know in advance if my web app will be run on a server with .NET 2 or 3.5. So it is limited to .NET 2 API calls only.

Thanks

A: 

Did you try the ConfigurationManager class?

Ikaso
In .NET 2.0 the ConfigurationManager class has a HttpModulesSection that reads from system.web/httpModules but does not have a ModulesSection that reads from system.webServer/modules. Hence the question as asked.
JK
A: 

You need to use the Microsoft.Web.Administration.dll assembly. You can check this blog post.

korchev
I am developing on XP, with IIS6 installed. There is no Microsoft.Web.Administration.dll. I'm looking for a solution that can be coded on .NET 2.0. My web app might be installed on a .NET2 box or a .NET 3.5 box (I have no control over this). So it has to be have code that says "if system.webServer exists, add the module there, else add the module to system.web". Right now I'm having to go with reading web.config as an xml document instead (which doesn't feel right).
JK