我们需要通过选择SSL证书为现有网站添加子域,但是我们收到以下错误消息。
但是,在IIS中创建了一个新的子域,但未选择SSL证书。
static void Main(string[] args)
{
string p = AppDomain.CurrentDomain.BaseDirectory;
string certPath = p + @"SSL File\IIS SSL Certificate.cer";
string certPass = "12345";
X509Certificate2 certifikat = new X509Certificate2(certPath, certPass, X509KeyStorageFlags.DefaultKeySet);
using (ServerManager manager = new ServerManager())
{
string siteName = "xxx";
Site site = manager.Sites.Where(q => q.Name == siteName).FirstOrDefault();
if (site == null)
{
throw new Exception("The specified site name does not exist in IIS!");
}
else
{
var binding = site.Bindings.Add("*:443:", certifikat.GetCertHash(), "Personal");
manager.CommitChanges();
}
}
}