iis 6 - How to get a list of sites and SSL certificates from IIS 6.0 using C#, WMI, and/or System.Management? -



iis 6 - How to get a list of sites and SSL certificates from IIS 6.0 using C#, WMI, and/or System.Management? -

i trying export ssl certificates on iis 6.0 sites specificed remote server centralized backup server can migrate and/or backup our ssl certificates, cannot figure out how iis 6.0 (all our servers in staging , production still run iis 6.0). there way c# , system.management targeting iis 6.0 web sites. have tried think of.

pseduo logic: list of iis web sites on server x if site has ssl certificate binding associated it, export ssl certificate name of iis web site.

here’s code closer need for iis 7.0:

using (servermanager servermanager = servermanager.openremote(this.servername)) { string collectiondisplay = null; if (servermanager.sites != null) collectiondisplay = "there " + servermanager.sites.count.tostring() + " sites:\n\n"; string sitedisplay = null; foreach (site site in servermanager.sites) { sitedisplay = sitedisplay + site.name + ": id = " + site.id + "\n"; // display each property of each bindings. string bindingdisplay = null; foreach (binding binding in site.bindings) { if (binding.protocol == "https") { bindingdisplay = bindingdisplay + " binding:\n bindinginformation: " + binding.bindinginformation; // there certificatehash , certificatestorename https protocol only. bindingdisplay = bindingdisplay + "\n certificatehash: " + binding.certificatehash + ": "; //add certificate hash collection if (!iiscertificatehashcollection.containskey(binding.certificatehash)) { iiscertificatehashcollection.add(binding.certificatehash, site.name); //iiscertificatehashcollection.add(new keyvaluepair<string, byte[]>(site.name, binding.certificatehash)); } // display hash. foreach (system.byte certhashbyte in binding.certificatehash) { bindingdisplay = bindingdisplay + certhashbyte.tostring() + " "; } bindingdisplay = bindingdisplay + "\n certificatestorename: " + binding.certificatestorename; } bindingdisplay = bindingdisplay + "\n endpoint: " + binding.endpoint; bindingdisplay = bindingdisplay + "\n host: " + binding.host; bindingdisplay = bindingdisplay + "\n isipporthostbinding: " + binding.isipporthostbinding; bindingdisplay = bindingdisplay + "\n protocol: " + binding.protocol; bindingdisplay = bindingdisplay + "\n tostring: " + binding.tostring(); bindingdisplay = bindingdisplay + "\n usedsmapper: " + binding.usedsmapper + "\n\n"; } sitedisplay = sitedisplay + bindingdisplay; } collectiondisplay = collectiondisplay + sitedisplay + "\n"; }

here’s code can’t quite get/don't know how obtain needed info iis 6.0, cannot query correct:

// connection succeeds, there no issue (left out code in sample) managementscope scope = new managementscope(string.format(@"\\{0}\root\cimv2", servername, options)); //managementscope scope = new managementscope(string.format(@"\\{0}\root\microsoftiisv2", servername, options)); scope.connect(); objectquery oq = new objectquery(@"select * win32_ntdomain"); managementobjectsearcher query = new managementobjectsearcher(scope, oq); managementobjectcollection querycollection = query.get(); foreach (managementobject mo in querycollection) { foreach (propertydata pd in mo.properties) { } }

you can utilize system.directoryservices certificate hash on iis6:

directoryentry dir = new directoryentry(@"iis://localhost/w3svc/1"); //this metabase path propertyvaluecollection vals = dir.properties[sslcerthash]; //this propertyname

the rest same in iis7.

hope helps, rotem varon

c# iis-6 wmi system.management

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -