c# - Blazor - app.UseIdentityServer(); 使用 .pfx 密钥文件 - 解析数字时遇到意外字符
问题描述
我创建了一个新的 Blazor WebAssembly 应用程序,其中包含个人用户帐户、应用程序内存储用户帐户和托管在 .NET 5 中的 ASP.NET Core。将我的应用程序部署到 Azure 应用程序服务时,出现以下错误:
对象引用未设置为对象的实例。在 Microsoft.Extensions.DependencyInjection.IdentityServerBuilderConfigurationExtensions
阅读这些链接,我必须为 IdentityServer 提供我自己的生产证书:
Blazor Web Assembly App .Net Core Hosted:发布运行时错误
https://stackoverflow.com/a/56904000/3850405
然后我创建了一个.pfx
这样的文件,我已经验证它可以工作并且我的密码是正确的。
https://stackoverflow.com/a/48790088/3850405
然后我将.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 上都不起作用。它失败并app.UseIdentityServer();
出现Startup.cs
以下错误:
Newtonsoft.Json.JsonReaderException:'解析数字时遇到意外字符:�. 路径'',第 1 行,位置 1。
根据 Microsoft 文档,我的证书应该是有效的:
用于签署令牌的生产证书。
- 该证书没有具体要求;它可以是自签名证书或通过 CA 机构提供的证书。
- 它可以通过 PowerShell 或 OpenSSL 等标准工具生成。
- 它可以安装到目标计算机上的证书存储中,也可以部署为具有强密码的 .pfx 文件。
如果我像这样加载密钥,它可以工作:
"Key": {
"Type": "Store",
"StoreName": "My",
"StoreLocation": "CurrentUser",
"Name": "CN=blazortest"
}
解决方案
我可以通过删除appsettings.Development.json中的 IdentityServer 条目来解决这个问题。
从 appsettings 中删除以下行。开发.json:
"IdentityServer": {
"Key": {
"Type": "Development"
}
}
推荐阅读
- dataframe - 如何使用谷歌表格在一张图表上绘制具有不同水平范围的多条线?
- html - 为什么100vh不走全屏?
- java - 如果用户不必要地单击保存按钮并且没有要保存的内容,如何检查 java?
- autorest - AutoRest v3 按控制器拆分 Rest Client
- asp.net-mvc - Knockout.js 中的数据绑定
- owasp - 如何在命令行中运行 ZAP 扫描?
- reactjs - 如何在使用反应测试库单击父组件上的按钮后测试子组件呈现文本?
- c# - 如何在更新中每次使用 foreach 循环一次,并且每次都使用 bool 标志?
- java - 用 spock 嘲笑的价值观不会延续到 Kotlin 吗?
- python - 使用 groupby 的 SimpleImputer