配置http时可以直接通过urls简单配置,多个配置用分号分割
{
"urls": "http://*:8080", //"urls": "http://*:8080;http://*:8081"
}
需要配置https时候需要指定证书文件
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
},
"Https": {
"Url": "https://localhost:5001",
"Certificate":{
"Path":"C:\\Service\\ServerCert.pfx",
"Password":"test"
}
}
}
}
}
需要生成证书文件时可以通过以下powershell获取,注意证书密码和保存路径,建议保存成脚本文件(GenCer.ps1)
$thumbPrint = $null
$certs = get-childitem cert:\\LocalMachine\\my
foreach ($certItem in $certs)
{
$certItem.Issuer
if ($certItem.Issuer -eq "CN=localhost")
{
$thumbPrint = $certItem.Thumbprint
break
}
}
Write-Host $thumbPrint
if ($null -ne $thumbPrint){
$mypwd = ConvertTo-SecureString -String "magicdrawing" -Force -AsPlainText
Get-ChildItem -Path cert:\localMachine\my\$thumbPrint | Export-PfxCertificate -FilePath .\ServerCert.pfx -Password $mypwd
Write-Host "Export IIS Express cert as Pfx file sucessfully."
}
else {
Write-Host "Can't find IIS Express cert."
}
标签:http,certItem,Host,cert,https,thumbPrint,net7
From: https://www.cnblogs.com/ives/p/17808519.html