[英]How to Enable HTTPS in IIS using C#?
Programmatically (C#) I want to configure IIS site in https. 我要以编程方式(C#)在https中配置IIS站点。 I have created a self-signing certificate and manually configured the site.
我创建了一个自签名证书,并手动配置了该站点。 But I want to automate this process using C#.
但是我想使用C#自动执行此过程。 I can't find a proper solution anywhere.
我在任何地方都找不到合适的解决方案。 Can someone help me with this?
有人可以帮我弄这个吗?
Finally, I got the solution. 最后,我找到了解决方案。 This is the code i wanted.
这是我想要的代码。
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.