无法从 Azure KeyVault 读取值。指定的用户没有有效的配置文件

Not able to read values from Azure KeyVault. The specified user does not have a valid profile

我们有多个服务器,在这些服务器上我们在 IIS 上托管了一个 ASP.NET 网站。在网站中,我们正尝试从 Azure KeyVault 获取值。

在一台服务器中,由于某种原因,它无法从 Azure KeyVault 中读取值,并出现错误 'The specified user does not have a valid profile'。我们已经完成调查、仔细检查配置、文件权限 - 一切看起来都很好。还尝试在 IIS 中调整配置文件,但没有任何帮助。

这是堆栈跟踪:

Exception information: 
    Exception type: ConfigurationErrorsException 
    Exception message: An error occurred loading a configuration file: The specified user does not have a valid profile.  Unable to load 'Microsoft.Configuration.ConfigurationBuilders.Azure, Version=2.0.0.0, Culture=neutral'. (D:\<website_path> line 77)
   at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
   at System.Web.Util.AppSettings.GetAppSettingsSection()
   at System.Web.Util.AppSettings.EnsureSettingsLoaded()
   at System.Web.Util.AppSettings.get_PortableCompilationOutput()
   at System.Web.Compilation.BuildManager.RestorePortableCompilationOutputSnapshot()
   at System.Web.Compilation.BuildManager.ExecutePreAppStart()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
The specified user does not have a valid profile.  Unable to load 'Microsoft.Configuration.ConfigurationBuilders.Azure, Version=2.0.0.0, Culture=neutral'.
   at System.Configuration.TypeUtil.GetTypeImpl(String typeString, Boolean throwOnError)
   at System.Configuration.ConfigurationBuildersSection.InstantiateBuilder(ProviderSettings ps)
   at System.Configuration.ConfigurationBuildersSection.GetBuilderFromName(String builderName)
   at System.Configuration.BaseConfigurationRecord.GetSectionXmlReader(String[] keys, SectionInput input)

有没有人遇到过类似的问题?

任何帮助将不胜感激。

我在这里回答过类似的问题:

一定要退房 - 可能是出于同样的原因。可能有一个 nuget 包需要不同版本的 Microsoft.Configuration.ConfigurationBuilders.Azure:2.0.0。但是,您安装的版本不兼容。

调试后我们发现了问题。事实证明,在用户的环境变量下,我们的一切都是正确的,但在系统的环境变量下,我们输入了错误的 AZURE_TENTANT_ID。解释为什么它作为控制台应用程序(运行 作为当前用户)而不是作为 Windows 服务(运行 作为系统)