c# - Encrypting Connection String also adds empty elements in web.config -


why code, adds useless empty elements in web.config? note: custom action advanced installer, , worked fine before.

the 2 lines i've added work advanced installer,

var map = new execonfigurationfilemap { execonfigfilename = path }; var config = configurationmanager.openmappedexeconfiguration(map, configurationuserlevel.none);

advanced installer: custom action encrypt connection sting.

[customaction] public static actionresult encryptconnstr(session session) {     try     {         var delimiter = '|';         var actiondata = session["customactiondata"];         var dataarray = actiondata.split(delimiter);         var server = dataarray[0];         var database = dataarray[1];         var username = dataarray[2];         var password = dataarray[3];         var path = path.combine(dataarray[4], "web.config");         var connstr = buildconnstr(server, database, username, password);          var map = new execonfigurationfilemap { execonfigfilename = path };         var config = configurationmanager.openmappedexeconfiguration(map, configurationuserlevel.none);         var section = (connectionstringssection)config.getsection("connectionstrings");          // add connectionstrings element         section.connectionstrings.add(new connectionstringsettings(getconnectionstringname(), connstr));          // encrypt         section.sectioninformation.protectsection(connstrencryptionkey);          // save configuration file.         config.save(configurationsavemode.modified, true);          return actionresult.success;     }     catch (exception ex)     {         messagebox.show(ex.message + "trace: " + ex.stacktrace, ex.message);         throw;     } } 

web.config, useless empty elements

<?xml version="1.0" encoding="utf-8" standalone="yes"?>   <configuration>     <configprotecteddata />     <system.diagnostics />     <system.windows.forms />     <system.windows.forms.applicationconfigurationsection />     <uri />     <appsettings>       <add key="clientvalidationenabled" value="true" />       <add key="unobtrusivejavascriptenabled" value="true" />     </appsettings>     <system.web>       <anonymousidentification />       <authentication />       <authorization />       <clienttarget />       <deployment />       <devicefilters />       <fulltrustassemblies />       <healthmonitoring />       <hostingenvironment />       <httpcookies />       <httphandlers />       <httpmodules />       <identity />       <machinekey />       <membership />       <mobilecontrols />       <pages />       <partialtrustvisibleassemblies />       <processmodel />       <profile />       <protocols />       <rolemanager />       <securitypolicy />       <sessionpagestate />       <sessionstate />       <sitemap />       <trace />       <trust level="full" />       <urlmappings />       <webcontrols clientscriptslocation="/aspnet_client/{0}/{1}/" />       <webparts />       <webservices />       <xhtmlconformance />       <compilation debug="true" targetframework="4.5.1" />       <httpruntime targetframework="4.5.1" />       <globalization requestencoding="utf-8" responseencoding="utf-8"         fileencoding="utf-8" culture="en-us" uiculture="en-us" />       <customerrors mode="on" />       <caching>         <cache />         <outputcache />         <outputcachesettings />         <sqlcachedependency />       </caching>     </system.web>     <runtime>       <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">         <dependentassembly>           <assemblyidentity name="system.web.helpers" publickeytoken="31bf3856ad364e35" />           <bindingredirect oldversion="1.0.0.0-3.0.0.0" newversion="3.0.0.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="system.web.webpages" publickeytoken="31bf3856ad364e35" />           <bindingredirect oldversion="1.0.0.0-3.0.0.0" newversion="3.0.0.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="system.web.mvc" publickeytoken="31bf3856ad364e35" />           <bindingredirect oldversion="1.0.0.0-5.2.2.0" newversion="5.2.2.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="webgrease" publickeytoken="31bf3856ad364e35"             culture="neutral" />           <bindingredirect oldversion="0.0.0.0-1.5.2.14234" newversion="1.5.2.14234" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="newtonsoft.json" publickeytoken="30ad4fe6b2a6aeed"             culture="neutral" />           <bindingredirect oldversion="0.0.0.0-6.0.0.0" newversion="6.0.0.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="system.web.webpages" publickeytoken="31bf3856ad364e35" />           <bindingredirect oldversion="1.0.0.0-3.0.0.0" newversion="3.0.0.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="system.web.optimization" publickeytoken="31bf3856ad364e35" />           <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="1.1.0.0" />         </dependentassembly>         <dependentassembly>           <assemblyidentity name="microsoft.owin" publickeytoken="31bf3856ad364e35"             culture="neutral" />           <bindingredirect oldversion="0.0.0.0-3.0.1.0" newversion="3.0.1.0" />         </dependentassembly>       </assemblybinding>     </runtime>     <system.webserver>       <handlers>         <remove name="extensionlessurlhandler-integrated-4.0" />         <remove name="optionsverbhandler" />         <remove name="traceverbhandler" />         <add name="extensionlessurlhandler-integrated-4.0" path="*."           verb="*" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" />       </handlers>     </system.webserver>     <connectionstrings configprotectionprovider="dataprotectionconfigurationprovider">       <encrypteddata>         <cipherdata>           <ciphervalue>xxx</ciphervalue>         </cipherdata>       </encrypteddata>     </connectionstrings>     <system.net>       <authenticationmodules />       <connectionmanagement />       <defaultproxy />       <requestcaching />       <settings />       <webrequestmodules />       <mailsettings>         <smtp />       </mailsettings>     </system.net>     <system.runtime.caching>       <memorycache />     </system.runtime.caching>     <system.runtime.serialization>       <datacontractserializer />     </system.runtime.serialization>     <system.servicemodel>       <behaviors />       <bindings />       <client />       <comcontracts />       <diagnostics />       <extensions />       <protocolmapping />       <routing />        <servicehostingenvironment />       <services />       <standardendpoints />       <tracking />     </system.servicemodel>     <system.servicemodel.activation>       <diagnostics />       <net.pipe />       <net.tcp />     </system.servicemodel.activation>     <system.transactions>       <defaultsettings />     </system.transactions>     <system.web.extensions>       <scripting>         <scriptresourcehandler />         <webservices>           <authenticationservice />           <jsonserialization />           <profileservice />           <roleservice />         </webservices>       </scripting>     </system.web.extensions>     <system.xaml.hosting>       <httphandlers />     </system.xaml.hosting>     <system.xml.serialization>       <datetimeserialization />       <schemaimporterextensions />       <xmlserializer />     </system.xml.serialization>   </configuration> 

solution: set configurationsavemode minimal


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -