【发布时间】:2020-02-24 15:57:32
【问题描述】:
我正在努力将 SSL 证书支持添加到 VB.Net API,但我在通过代码使其工作时遇到了问题。如果我手动将证书导入 IIS,然后运行我的 netsh 命令,我可以让它工作。我有一个使用mkcert 创建的证书,并将其导入 IIS。
- 将证书导入 IIS
- cmd:
netsh http delete sslcert ipport=0.0.0.0:443 - 使用 https/443 baseurl 启动我的 API
- 这按预期工作。
当我尝试通过代码执行此操作时,它不起作用,我收到 netsh 错误a specified logon session does not exist。这是我用来导入和绑定证书的代码。
' Import the certificate into IIS LocalComputer, this is needed for the ip address bindings.
Dim IIS = New X509Store(StoreName.My, StoreLocation.LocalMachine)
IIS.Open(OpenFlags.ReadWrite)
Try
For Each certificate As X509Certificate2 In x509
IIS.Add(certificate)
Next
Finally
IIS.Close()
End Try
' Bind the SSL Cert to the network address and port.
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
Dim cmd As String = " /K " + "netsh http add sslcert ipport=0.0.0.0:" + port.ToString() + " certhash=" + CertificateThumbprint + " appid={myAppId}"
Console.WriteLine(cmd)
pi.Arguments = cmd
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
【问题讨论】:
-
PInvoke HTTP API,你会得到你想要的,github.com/jexuswebserver/JexusManager/blob/v13.0.0.21/…
标签: vb.net iis-7 ssl-certificate iis-7.5 netsh