Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, please I need some assistance before I tear my eyeballs out lol... XD

I am trying to add the below node to web.config under system.web...

XML
<identity impersonate="true" password="password" userName="userName" />


Using (Microsoft.Web.Administration) library however I am failing badly.

What I have tried:

The below code is where I am at.

C#
Configuration config = serverManager.GetWebConfiguration("Default Web Site");
ConfigurationSection applicationPoolsSection = config.GetSection("system.web"); // ===> This says that I need an extra //section, if I change it to "system.web/?" ?=anything... it will fail at addElement.
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();

ConfigurationElement addElement = applicationPoolsCollection.CreateElement("identity");
addElement["key"] = "impersonate";
addElement["value"] = "true";

applicationPoolsCollection.Add(addElement);

serverManager.CommitChanges();



Below is the snippet of my web.config...
XML
<system.web>
<!--Some code here including handlers....-->
<!--The below line needs to be added at runtime from a different app as the installer (made by someone else) creates the app and pools in IIS-->
   <identity impersonate="true" password="password" userName="username" />
		
</system.web>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900