简体   繁体   English

.net5 secrets.json 未在本地使用

[英].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.

相关问题 .net 5,secrets.json,appsettings.json 和 Z3A580F142203677F1F0BC3089 应用程序设置 - .net 5, secrets.json, appsettings.json and Azure Application Settings 如何在asp.net core 2.1中部署secrets.json - How to Deploy secrets.json in asp.net core 2.1 找不到配置文件“secrets.json”并且不是可选的(.NET 6) - the configuration file 'secrets.json' was not found and is not optional (.NET 6) 如何在授权过滤器中获取 secrets.json 或 azure 机密? - How do I get secrets.json or azure secrets in an Authorization filter? VS2022 配置 Azure keyvault 看不到本地 secrets.json - VS2022 Configure Azure keyvault not seeing local secrets.json 错误:值不能为 null。(参数“connectionString”)+ 迁移 + secrets.json - Error: Value cannot be null. (Parameter 'connectionString') + Migrations + secrets.json wwwroot中的vNext / .NET5 config.json - vNext / .NET5 config.json in wwwroot .NET Arch Linux 上的 6:未读取用户机密 - .NET 6 on Arch Linux: User Secrets not being read 如何 model 目标 class 用于接收 JSON ZFC35FDC70D5FC69D269883A82NET57A 响应。 - How to model a target class for receiving a JSON html response in .NET5 Net5 上的 ServiceProcessInstaller 在哪里? - Where is ServiceProcessInstaller on Net5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM