Arch Linux 上的 .NET 6:未读取用户机密
.NET 6 on Arch Linux: User Secrets not being read
我正在 Arch Linux 上的 .NET 6 应用程序中工作。 code is open-source.
我确定 ASPNETCORE_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!!!");
}
当我 运行 带有 dotnet run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj
的应用程序时,我可以看到上面的消息。
在我的 appsettings.json
和 appsettings.Development.json
中,我没有设置任何变量。
我确实设置了用户机密。当我 运行 dotnet 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;
然而,当我 运行 带有 dotnet 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)
找不到 ClientId here。我什至在 Rider 中进行了调试,我可以看到当我越过那条线时,ClientId 确实是 null
.
我错过了什么?在过去的 2 天里,我一直在为此苦苦挣扎,我不明白为什么我的用户机密没有被读取。
使用 user-secrets
时 - 您应该用冒号 (:
) 分隔各个部分,而不是 double-underscore (__
)。
这有点令人困惑,我知道,但是双下划线用于环境变量,而用户机密实际上并不是环境变量。
你可以看到 MSDN's examples 反映了这一点。
我正在 Arch Linux 上的 .NET 6 应用程序中工作。 code is open-source.
我确定 ASPNETCORE_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!!!");
}
当我 运行 带有 dotnet run --project Bejebeje.Mvc/Bejebeje.Mvc.csproj
的应用程序时,我可以看到上面的消息。
在我的 appsettings.json
和 appsettings.Development.json
中,我没有设置任何变量。
我确实设置了用户机密。当我 运行 dotnet 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;
然而,当我 运行 带有 dotnet 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)
找不到 ClientId here。我什至在 Rider 中进行了调试,我可以看到当我越过那条线时,ClientId 确实是 null
.
我错过了什么?在过去的 2 天里,我一直在为此苦苦挣扎,我不明白为什么我的用户机密没有被读取。
使用 user-secrets
时 - 您应该用冒号 (:
) 分隔各个部分,而不是 double-underscore (__
)。
这有点令人困惑,我知道,但是双下划线用于环境变量,而用户机密实际上并不是环境变量。
你可以看到 MSDN's examples 反映了这一点。