简体   繁体   English

.NET Arch Linux 上的 6:未读取用户机密

[英].NET 6 on Arch Linux: User Secrets not being read

I am working in a .NET 6 application on Arch Linux. The code is open-source .我在 Arch Linux 上的 .NET 6 应用程序中工作。代码是开源的

I am certain that AS.NETCORE_ENVIRONMENT is set to Development because I updated the code in my Program.cs to be:我确定AS.NETCORE_ENVIRONMENT设置为Development ,因为我将Program.cs中的代码更新为:

if (!app.Environment.IsDevelopment())
{
  app.UseExceptionHandler("/Error");

  // the default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  app.UseHsts();
}
else
{
  Console.WriteLine("We are in development environment!!!");
}

And when I run the application with do.net run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj I can see my above message.当我使用do.net run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj应用程序时,我可以看到上面的消息。

In my appsettings.json and appsettings.Development.json I don't have any variables set.在我的appsettings.jsonappsettings.Development.json我没有设置任何变量。

I do have user-secrets set.我确实设置了用户机密。 When I run do.net user-secrets list --project Bejebeje.Mvc I get:当我运行do.net user-secrets list --project Bejebeje.Mvc我得到:

Sentry__SendDefaultPii = true
Sentry__MinimumEventLevel = Warning
Sentry__MinimumBreadcrumbLevel = Debug
Sentry__IncludeRequestPayload = true
Sentry__Dsn = https://blah@blah.ingest.sentry.io/blah
Sentry__DiagnosticsLevel = Error
Sentry__Debug = true
Sentry__AttachStackTrace = true
IdentityServerConfiguration__ClientSecret = blah
IdentityServerConfiguration__ClientId = blah
IdentityServerConfiguration__Authority = https://cognito-idp.eu-central-1.amazonaws.com/eu-central-blah/
ConnectionString = Server=localhost;Port=5432;Database=bejebeje;User Id=postgres;Password=admin;

Yet when I run the application with do.net run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj I get:然而,当我使用do.net run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj应用程序时,我得到:

We are in development environment!!!
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/j/code/bejebeje/Bejebeje.Mvc/
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.ArgumentException: Options.ClientId must be provided (Parameter 'ClientId')
         at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions.Validate()
         at Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.Validate(String scheme)
         at Microsoft.AspNetCore.Authentication.AuthenticationBuilder.<>c__DisplayClass4_0`2.<AddSchemeHelper>b__1(TOptions o)
         at Microsoft.Extensions.Options.ValidateOptions`1.Validate(String name, TOptions options)
         at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
         at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass10_0.<Get>b__0()
         at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
         at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
         at System.Lazy`1.CreateValue()
         at System.Lazy`1.get_Value()
         at Microsoft.Extensions.Options.OptionsCache`1.GetOrAdd(String name, Func`1 createOptions)
         at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name)
         at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Sentry.AspNetCore.SentryTracingMiddleware.InvokeAsync(HttpContext context) in /_/src/Sentry.AspNetCore/SentryTracingMiddleware.cs:line 106
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

It can't find the ClientId here .它在这里找不到 ClientId I even debugged in Rider, and I can see that when I go past that line, ClientId is indeed null .我什至在 Rider 中进行了调试,我可以看到当我 go 越过该行时,ClientId 确实是null

What am I missing?我错过了什么? I've been struggling with this for the past 2 days and I can't figure out why my user secrets aren't being read.在过去的 2 天里,我一直在为此苦苦挣扎,我不明白为什么我的用户机密没有被读取。

When using user-secrets - you should separate sections with a colon ( : ) instead of a double-underscore ( __ ).使用user-secrets时 - 您应该使用冒号 ( :而不是双下划线 ( __ ) 分隔各部分。
It is a bit confusing, I know, but double underscores are used for environment variables, whereas user secrets are not actually environment variables.我知道这有点令人困惑,但是双下划线用于环境变量,而用户机密实际上并不是环境变量。
You can see MSDN's examples reflect this.您可以看到MSDN 的示例反映了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM