Wednesday 15 July 2015

c# - Change web.config security mode pragmatically (edit XML file) -



c# - Change web.config security mode pragmatically (edit XML file) -

if have config looks this...

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.servicemodel> <services> </services> <bindings> <basichttpbinding> <binding name="serviceconfiguration" closetimeout="00:01:00" opentimeout="00:01:00" receivetimeout="00:01:00" sendtimeout="00:01:00" maxreceivedmessagesize="33554432" messageencoding="text" textencoding="utf-8"> <readerquotas maxdepth="32" maxstringcontentlength="524288" maxarraylength="1048576" maxbytesperread="4096" maxnametablecharcount="16384" /> <security mode="transportcredentialonly"> <transport clientcredentialtype="windows" /> </security> </binding> </basichttpbinding> </bindings> </system.servicemodel> </configuration>

i alter

<security mode="transportcredentialonly"> <security mode="transport">

<transport clientcredentialtype="windows" /> <transport clientcredentialtype="none" />

so far have read xml file , read security node

webconfig = @"c:\xml.xml"; xmldocument myxmldocument = new xmldocument(); myxmldocument.load(webconfig); xmlnodelist oldnodes; oldnodes = myxmldocument.getelementsbytagname("security");

but i'm unsure how alter xml nodes , save file.

we need have alter configs manually after deployment , there hundreds of them, i'm pragmatically recursively going through files , ending them.

in case want go on using xmldocument, can follow illustration select element name , specific attribute value :

.... //select <security> element having mode attribute value equals "transportcredentialonly" xmlnode security = myxmldocument.selectsinglenode("//security[@mode='transportcredentialonly']"); if(security != null) { //edit attribute value security.attributes["mode"].value = "transport"; } .... //save edited xmldocument file myxmldocument.save(webconfig);

c# xml xmldocument

No comments:

Post a Comment