[英].net5 secrets.json not being used locally
I have a .net5 web app in which I am trying to add a secrets.json file so I have right clicked and created the file - in my project file I can see:我有一个 .net5 web 应用程序,我试图在其中添加一个 secrets.json 文件,所以我右键单击并创建了该文件 - 在我的项目文件中我可以看到:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>1cb5a573-309c-4b03-b7e9-3c09794038bb</UserSecretsId>
</PropertyGroup>
The secrets.json file exists in AppData\Roaming\Microsoft\UserSecrets\1cb5a573-309c-4b03-b7e9-3c09794038bb: AppData\Roaming\Microsoft\UserSecrets\1cb5a573-309c-4b03-b7e9-3c09794038bb 中存在 secrets.json 文件:
{
"GraphApi": {
"ClientSecret": "secret-key"
},
}
In my appsettings.json:在我的 appsettings.json 中:
"GraphApi": {
"TenantId": "tenant-id",
"Scopes": ".default",
"ClientId": "client-id",
"ClientSecret": "From user secrets"
},
and in my program.cs:在我的 program.cs 中:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureAppConfiguration((hostContext, builder) =>
{
if (hostContext.HostingEnvironment.IsDevelopment())
{
// Use user secrets for local development
builder.AddUserSecrets<Program>();
}
});
however, it's not picking up my ClientSecret
from the secrets.json - if I put the value in appsettings.json, it works just fine - is there anything else I need to do to make it work?但是,它没有从 secrets.json 中获取我的
ClientSecret
- 如果我将值放入 appsettings.json,它工作得很好 - 我还需要做些什么才能让它工作吗?
Turns out there was a web.config that was added to the project and in that it wsa pointing the project to use the appsettings.development version which was overriding the secrets:原来有一个 web.config 添加到项目中,它 wsa 指向项目使用覆盖秘密的 appsettings.development 版本:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\Debug\net5.0\Project.WebApp.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="443" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Deleting this file and re-configuring the project to use iis express instead of iis fixed the issue删除此文件并重新配置项目以使用 iis express 而不是 iis 解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.