.net5 .net6 .net7指定发布端口 http https

配置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."
}
posted @ 2023-11-03 21:12  Hey,Coder!  阅读(67)  评论(0编辑  收藏  举报