IIS 6.0 サイトのすべての SSL 証明書を特定のリモート サーバーから集中バックアップ サーバーにエクスポートして、SSL 証明書を移行および/またはバックアップできるようにしようとしていますが、IIS 6.0 でこれを行う方法がわかりません (すべてのステージングおよび運用中のサーバーは引き続き IIS 6.0 を実行します)。IIS 6.0 Web サイトをターゲットにするために C# と System.Management を使用する方法はありますか。考えられることはすべて試しました。
疑似ロジック: サーバー X 上のすべての IIS Web サイトのリストを取得する サイトに SSL 証明書バインディングが関連付けられている場合は、IIS Web サイトの名前で SSL 証明書をエクスポートします。
IIS 7.0 に必要なものに近いコードを次に示します。
using (ServerManager serverManager = ServerManager.OpenRemote(this.ServerName))
{
string collectionDisplay = null;
if (serverManager.Sites != null)
collectionDisplay = "There are " + 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 is a CertificateHash and CertificateStoreName for the https protocol only.
bindingDisplay = bindingDisplay + "\n CertificateHash: " +
binding.CertificateHash + ": ";
//Add the certificate hash to the collection
if (!IisCertificateHashCollection.ContainsKey(binding.CertificateHash))
{
IisCertificateHashCollection.Add(binding.CertificateHash, site.Name);
//IisCertificateHashCollection.Add(new KeyValuePair<string, byte[]>(site.Name, binding.CertificateHash));
}
// Display the 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";
}
これは、IIS 6.0 から必要な情報を取得する方法を完全に取得できない/わからないコードです。クエリを正しく取得できません。
// Connection succeeds, so there is no issue with that (left out code for that 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 * FROM Win32_NTDomain");
ManagementObjectSearcher query = new ManagementObjectSearcher(scope, oq);
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
foreach (PropertyData pd in mo.Properties)
{
}
}