我使用以下代码在IIS中创建了一个网站:
我在服务器证书下从IIS导出了一个证书来使用:
name = "TestSite"
port = 5858
location = location of my install files.
using (ServerManager iisManager = new ServerManager())
{
Site website = iisManager.Sites.Add(name, location, port);
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
X509Certificate2 certificate = new X509Certificate2(@"c:certstestwcf.pfx",
"pwd>");
store.Add(certificate);
var binding = website.Bindings.Add("*:443:", certificate.GetCertHash(), store.Name);
binding.Protocol = "https";
store.Close();
website.Applications[0].ApplicationPoolName = appPoolName;
website.ServerAutoStart = true;
iisManager.CommitChanges();
}
现在发生的是,如果我从Visual Studio运行任何其他开发解决方案我得到错误:
"An error occurred while using SSL configuration for endpoint 0.0.0.0:87879. The
error status code is contained within the returned data."
当开发站点出现时,它重定向到localhost,我似乎无法到达https://localhost:87879,它使用IIS Express。
我不知道如何,但我认为我已经打破了IIS中影响本地主机的绑定我从哪里开始看这个,有什么主意吗?
成功了。对于任何有此问题的人,请尝试以下操作:
从提升的命令提示符运行:
cd C:Program Files (x86)IIS Express IisExpressAdminCmd.exesetupsslUrl -url:urlToYourSite -UseSelfSigned
用url代替urlToYourSite。
。
cd C:Program Files (x86)IIS ExpressIisExpressAdminCmd.exe setupsslUrl -url:https://localhost:44387/-UseSelfSigned