有谁能举例说明如何在没有IIS的情况下自行托管核心的web?我已经在IIS中托管了,但是我想完成自我托管,同时我也希望为自宿主web API启用HTTPS。
发布于 2020-06-22 12:53:52
在提升的控制台(“以管理员身份运行”)上,执行netsh http add urlacl url=https://+:4443/ user=<your user name>
以允许运行中的用户使用HTTPS监听端口4443 (注意在上面的命令中使用了https
而不是http
)。
也是在提升的控制台上,通过运行
netsh http add sslcert ipport=0.0.0.0:port certhash=thumbprint appid={
app-guid
}
其中,端口是侦听端口(例如4443);特殊IP地址0.0.0.0匹配本地计算机的任何IP地址;拇指打印是证书的SHA-1散列,以十六进制表示;app-guid是用于标识所属应用程序的任何GUID (例如,{00000000-0000-0000-000000000000})。编写自主机配置,如
class MyHttpsSelfHostConfiguration : HttpSelfHostConfiguration
{
public MyHttpsSelfHostConfiguration(string baseAddress): base(baseAddress){}
public MyHttpsSelfHostConfiguration(Uri baseAddress) : base(baseAddress){}
protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
{
httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
return base.OnConfigureBinding(httpBinding);
}
}
然后更改传递给MyHttpsSelfHostConfiguration(“https://localhost:4443”);构造函数的基本地址: var config =新的MyHttpsSelfHostConfiguration
https://stackoverflow.com/questions/62514699
复制相似问题