如何在本地测试时轻松启用azure函数HTTPS [英] How to enable azure function https easily when do local test
本文介绍了如何在本地测试时轻松启用azure函数HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在Windows上本地测试Azure函数http触发器。
我使用azure-Function-core-Tools运行命令,如下所示func start --port 5007 --useHttps
然后我收到错误:自动证书生成当前在.NET核心内部版本上不起作用。
看起来我应该像这样使用命令func start --port 5007 --useHttps --cert certificate.pfx
在本地创建自签名证书之后。
是否有方法可以轻松启用HTTPS?
就像我使用.Net核心WebAPI时一样,我可以轻松地导出env:ASPNETCORE_URLS=https://localhost。点击某个按钮后,我就可以很好地使用HTTPS了。 我们有这样的东西吗?或者如果func start --port 5007 --useHttps
就足够了,但我错过了某些配置?
谢谢!
推荐答案
更新答案:
func start --port 5007 --useHttps
将不会在Azure函数v1之后自动创建证书。基于.Net Core的Azure Function v2和Azure Function v3工具不会为您创建证书。您应该强制生成证书。
原始答案:
我可以重现您的错误:
解决方案:
使用管理员启动PowerShell,转到Function应用程序文件夹,然后使用以下命令:
$cert = New-SelfSignedCertificate -Subject localhost -DnsName localhost -FriendlyName "Functions Development" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
然后创建证书文件:
Export-PfxCertificate -Cert $cert -FilePath certificate.pfx -Password (ConvertTo-SecureString -String 123 -Force -AsPlainText)
我终于可以使用HTTPS:(下面的命令在Windows cmd中运行。)
func host start --port 5007 --useHttps --cors * --cert certificate.pfx --password 123
这篇关于如何在本地测试时轻松启用azure函数HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文