以编程方式(C#)我想在https中配置IIS站点。我创建了一个自签名证书并手动配置了该站点。但是我想用C#自动化这个过程。我无法在任何地方找到合适的解决方案。有人可以帮我弄这个吗?
最后,我得到了解决方案。这是我想要的代码。
ServerManager serverManager = new ServerManager();
Site mySite = serverManager.Sites.Add(siteName.ToString(), "http", "*:80:" + domainName, physicalPath);
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
X509Certificate2 certificate = new X509Certificate2("SSL server certificate", "password", X509KeyStorageFlags.Exportable);
store.Add(certificate);
var binding = mySite.Bindings.Add("*:443:" + domainName, certificate.GetCertHash(), "My");
binding.Protocol = "https";
mySite.ApplicationDefaults.ApplicationPoolName = siteName;
serverManager.CommitChanges();
store.Close();