读取密钥环时发生错误,但我什至不使用 DataProtection 密钥功能

问题描述 投票:0回答:1

我在嵌入式 Linux 系统 (Ubuntu) 上运行的程序中使用 ASP.NET Core 3.1 / C# 来访问 HTTP 网页(不安全)。

包含操作系统和程序的系统映像对于我公司准备的所有嵌入式平台都是相同的,并且一切正常 - 我可以毫无问题地访问网页。

近期部分版块出现网页显示错误的情况。在这些上,当程序启动时,我收到此错误:

失败: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider[48]
读取钥匙圈时发生错误。

System.Xml.XmlException:根元素丢失。在 System.Xml.XmlTextReaderImpl.Throw(异常 e) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() 位于 System.Xml.XmlTextReaderImpl.Read() 位于 System.Xml.XmlReader.MoveToContent() 位于 System.Xml.Linq.XElement.Load(XmlReader阅读器,LoadOptions选项)
在 System.Xml.Linq.XElement.Load(流流,LoadOptions 选项)
在 System.Xml.Linq.XElement.Load(Stream 流) 处 Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.ReadElementFromFile(字符串 完整路径)位于 Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElementsCore()+MoveNext() 在 System.Collections.Generic.List

1..ctor(IEnumerable
1 个集合)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源) 处 Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElements() 在 Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys() 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset 现在,IKey keyJustAdded) 位于 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset) 现在)在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow,布尔强制刷新)

我不在我的应用程序中使用此“数据保护密钥”功能。如何禁用此功能?

c# asp.net-core embedded
1个回答
0
投票

此链接帮助我理解问题https://learn.microsoft.com/en-us/answers/questions/2180/server-exceptions-xmlexception-root-element-is-mis

~/.aspnet/DataProtection-Keys/ 内有一个空的数据保护密钥,删除最后一个可以解决问题。

按照本文所述使用

services.AddDataProtection().UseEphemeralDataProtectionProvider();
并不能避免存在无效 xml 文件时出现的异常。

由于我在嵌入式系统中使用 ASP.NET Core,可能会断电,并且无法阻止 ASP.NET Core 创建这些文件,因此我决定在应用程序启动时删除所有数据保护密钥文件。

© www.soinside.com 2019 - 2024. All rights reserved.