当使用.pfx
文件我收到以下错误:
Blazor - app.UseIdentityServer();使用 .pfx 密钥文件 - 解析数字时遇到意外字符 https://stackoverflow.com/questions/66448141/blazor-app-useidentityserver-with-pfx-key-file-unexpected-character-enco
我也使用了这个错误AddDeveloperSigningCredential
and AddSigningCredential
with services.AddIdentityServer()
.
具有个人帐户和 ASP.NET Core 托管的 Blazor WebAssembly 应用程序 - 未将对象引用设置为对象的实例 - AddSigningCredentials https://stackoverflow.com/q/69429340/3850405
我最终是这样解决的:
以管理员身份在 Powershell 中创建了一个新证书:
New-SelfSignedCertificate -DnsName "blazortest" -CertStoreLocation "cert:\CurrentUser\My"
应用程序设置.json:
"IdentityServer": {
"Clients": {
"BlazorTest.Client": {
"Profile": "IdentityServerSPA"
}
},
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "CN=blazortest"
}
},
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0#example-deploy-to-azure-app-service https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-3.0#example-deploy-to-azure-app-service
从以下位置删除了此内容appsettings.Development.json
:
"IdentityServer": {
"Key": {
"Type": "Development"
}
}
这在本地有效。然后我用了mmc.exe
将证书导出为.pfx
文件并通过上传Azure App Service
-> TLS/SSL settings
.
然后我用了Azure Cloud Shell
启用对证书的访问,如下所示:
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_CERTIFICATES=<comma-separated-certificate-thumbprints>
https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#load-the-certificate-in-code https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code#load-the-certificate-in-code
您还可以添加Certificate Thumbprint
手动添加WEBSITE_LOAD_CERTIFICATES
to Configuration
:
然后终于成功了!
如果您从 Azure Cloud Shell 收到如下错误:
ResourceGroupNotFound:找不到资源组“”。
确保您处于正确的订阅中,并使用以下命令设置正确的订阅:
az account show
az account list
az account set --subscription <subscriptionId>
如果您托管在IIS
你需要导入.pfx
证书给Personal
文件夹Local Computer
然后选择Manage Private Keys...
并授予运行该程序的用户访问权限Application Pool
.
托管在 GCP、Google Cloud Platform 上,如果您没有上传证书,您可能会看到与此类似的错误。
未处理的异常。 System.InvalidOperationException:找不到
“CurrentUser\My”上主题为“CN=blazortest”的有效证书
Linux 无法使用 Windows 证书存储来加载 TLS 证书,因此需要从文件加载证书: