Blazor - app.UseIdentityServer();使用 .pfx 密钥文件 - 解析数字时遇到意外字符

Blazor - app.UseIdentityServer(); with .pfx key file - Unexpected character encountered while parsing number

我创建了一个新的 Blazor WebAssembly 应用程序,其中包含个人用户帐户、在应用程序中存储用户帐户和 ASP.NET 核心托管在 .NET 5 中。将我的应用程序部署到 Azure 应用程序服务时,出现以下错误:

Object reference not set to an instance of an object.at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderConfigurationExtensions

阅读这些链接,我必须为 IdentityServer 提供我自己的生产证书:

Blazor Web Assembly App .Net Core Hosted: publish runtime error

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-5.0#example-deploy-to-azure-app-service

然后我创建了一个这样的 .pfx 文件,我已经验证它可以工作并且我的密码是正确的。

然后我将 .pfx 文件放在我的 Server 项目根文件夹中,并将 Copy to Output Directory 标记为 Copy Always

然后我将 appsettings.json 更新为如下所示:

  "IdentityServer": {
    "Clients": {
      "BlazorTest.Client": {
        "Profile": "IdentityServerSPA"
      }
    },
    "Key": {
      "Type": "File",
      "FilePath": "localhost.pfx",
      "Password": "MySercurePassword123?"
    }
  },

现在该项目在本地或 Azure 上都无法运行。它在 Startup.cs 中的 app.UseIdentityServer(); 上失败,并出现以下错误:

Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing number: �. Path '', line 1, position 1.'

根据 Microsoft 文档,我的证书应该有效:

用于签署令牌的生产证书。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-5.0#deploy-to-production

如果我像这样加载密钥,它会起作用:

"Key": {
  "Type": "Store",
  "StoreName": "My",
  "StoreLocation": "CurrentUser",
  "Name": "CN=blazortest"
}

我通过删除 appsettings.Development.json.

中的 IdentityServer 条目解决了这个问题

从 appsettings 中删除以下行。开发。json:

"IdentityServer": {
     "Key": {
       "Type": "Development"
     }
   }