使用 Services.AddAuthentication() 会导致应用程序在启动时停止

Using Services.AddAuthentication() causes application to stop on startup

提问人:Pietro di Caprio 提问时间:11/17/2023 最后编辑:Pietro di Caprio 更新时间:11/17/2023 访问量:67

问:

在基本的 Asp Net Core Web API 项目 ( , SDK 7.0 ) 中,通过dotnet new webapi

builder.Services.AddAuthentication()
        .AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>(
            BasicAuthenticationDefaults.AuthenticationScheme, null);

使应用程序在完成启动之前退出。启用详细日志记录后,可能会注意到,在执行调用时,它使用 DPAPI 解密密钥,并且突然停止,没有任何例外,也没有任何类型的日志,无论是在 Windows 的注册表中。app.Run()

[System         ][DBUG][23-11-17T14:27:54.9231+01:00][0][        Microsoft.Extensions.Hosting.Internal.Host]`Hosting starting`
[System         ][INFO][23-11-17T14:27:55.4962+01:00][0][NetCore.DataProtection.KeyManagement.XmlKeyManager]`User profile is available. Using 'C:\Users\p.dicaprio.extblar\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.`
[System         ][DBUG][23-11-17T14:27:55.5027+01:00][0][ataProtection.Repositories.FileSystemXmlRepository]`Reading data from file 'C:\Users\p.dicaprio.extblar\AppData\Local\ASP.NET\DataProtection-Keys\key-70202a7b-a057-403b-b974-5060170571f3.xml'.`
[System         ][DBUG][23-11-17T14:27:55.5232+01:00][0][NetCore.DataProtection.KeyManagement.XmlKeyManager]`Found key {70202a7b-a057-403b-b974-5060170571f3}.`
[System         ][DBUG][23-11-17T14:27:55.5363+01:00][0][re.DataProtection.KeyManagement.DefaultKeyResolver]`Considering key {70202a7b-a057-403b-b974-5060170571f3} with expiration date 2024-02-15 13:20:05Z as default key.`
[System         ][DBUG][23-11-17T14:27:55.5390+01:00][0][.AspNetCore.DataProtection.TypeForwardingActivator]`Forwarded activator type request from Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor, Microsoft.AspNetCore.DataProtection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 to Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor, Microsoft.AspNetCore.DataProtection, Culture=neutral, PublicKeyToken=adb9793829ddae60`
[System         ][DBUG][23-11-17T14:27:55.5429+01:00][0][ore.DataProtection.XmlEncryption.DpapiXmlDecryptor]`Decrypting secret element using Windows DPAPI.`

BasicAuthenticationHandler非常简单:它读取 Authorization 标头,从中删除并解码提供的 base64 凭据,以检查是否存在有效的键/值对。Basic: Dictionary<string,string>

关于验证什么有什么建议吗?

附言 它在我的机器上工作,它在服务器 A 上工作,它在服务器 B 上显示这个问题(完全不受我的控制)。
被 try/catch(Exception) 包围,但 catch 不提供任何日志。
app.Run()

C# asp.net ASP.NET 核心 DPAPI

评论


答: 暂无答案