用户机密路径:C:\Users{UserName}\AppData\Roaming\Microsoft\UserSecrets{ID}

    在项目文件中可以看到该用户机密的 ID:
    image.png
    右键文件标签,可以直接打开所在目录:
    image.png
    回顾 ASP.NET Core 程序配置信息来源:

    • appsettings.json
    • appsettings{环境变量}.json
    • 用户机密
    • 环境变量
    • 命令行参数

      1. builder.UseKestrel((builderContext, options) =>
      2. {
      3. options.Configure(builderContext.Configuration.GetSection("Kestrel"));
      4. })
      5. .ConfigureAppConfiguration((hostingContext, config) =>
      6. {
      7. var env = hostingContext.HostingEnvironment;
      8. config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
      9. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
      10. if (env.IsDevelopment())
      11. {
      12. var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
      13. if (appAssembly != null)
      14. {
      15. config.AddUserSecrets(appAssembly, optional: true);
      16. }
      17. }
      18. config.AddEnvironmentVariables();
      19. if (args != null)
      20. {
      21. config.AddCommandLine(args);
      22. }
      23. })
      24. ...