当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.AddUserSecrets方法代码示例

本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.AddUserSecrets方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddUserSecrets方法的具体用法?C# ConfigurationBuilder.AddUserSecrets怎么用?C# ConfigurationBuilder.AddUserSecrets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Extensions.Configuration.ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.AddUserSecrets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }

            // this file name is ignored by gitignore
            // so you can create it and use on your local dev machine
            // remember last config source added wins if it has the same settings
            builder.AddJsonFile("appsettings.local.overrides.json", optional: true);

            // most common use of environment variables would be in azure hosting
            // since it is added last anything in env vars would trump the same setting in previous config sources
            // so no risk of messing up settings if deploying a new version to azure
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            //env.MapPath
            appBasePath = appEnv.ApplicationBasePath;
        }
开发者ID:lespera,项目名称:cloudscribe,代码行数:28,代码来源:Startup.cs

示例2: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnvironment)
        {
            _appEnvironment = appEnvironment;
            _hostingEnvironment = env;

            var RollingPath = Path.Combine(appEnvironment.ApplicationBasePath, "logs/myapp-{Date}.txt");
            Log.Logger = new LoggerConfiguration()
                .WriteTo.RollingFile(RollingPath)
                .CreateLogger();
            Log.Information("Ah, there you are!");

            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddJsonFile("appsettings-filters.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            // Initialize the global configuration static
            GlobalConfigurationRoot.Configuration = Configuration;
        }
开发者ID:ghstahl,项目名称:vNext.Jan2016Web,代码行数:29,代码来源:Startup.cs

示例3: Startup

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("version.json")
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();

                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            else if (env.IsStaging() || env.IsProduction())
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: false);
            }

            Configuration = builder.Build();

            Configuration["version"] = new ApplicationEnvironment().ApplicationVersion; // version in project.json
        }
开发者ID:ChrisDobby,项目名称:allReady,代码行数:29,代码来源:Startup.cs

示例4: Startup

        public Startup(
            IHostingEnvironment env,
            IApplicationEnvironment appEnv)
        {
            _env = env;

            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                // standard config file
                .AddJsonFile("config.json")
                // environment specific config.<environment>.json file
                .AddJsonFile($"config.{env.EnvironmentName}.json", true /* override if exists */)
                // standard Windows environment variables
                .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                // this one adds not using directive to keep it secret, only a dnx reference
                // the focus is not on Secrets but on User, so these are User specific settings
                // we can also make it available only for developers
                builder.AddUserSecrets();
            }

            Configuration = builder.Build();
        }
开发者ID:madrus,项目名称:mvaWebApp02,代码行数:26,代码来源:Startup.cs

示例5: ConfigureConfiguration

        /// <summary>
        /// Creates and configures the application configuration, where key value pair settings are stored. See
        /// http://docs.asp.net/en/latest/fundamentals/configuration.html
        /// http://weblog.west-wind.com/posts/2015/Jun/03/Strongly-typed-AppSettings-Configuration-in-ASPNET-5
        /// </summary>
        /// <param name="hostingEnvironment">The environment the application is running under. This can be Development, 
        /// Staging or Production by default.</param>
        /// <returns>A collection of key value pair settings.</returns>
        private static IConfiguration ConfigureConfiguration(IHostingEnvironment hostingEnvironment)
        {
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            // Add configuration from the config.json file.
            configurationBuilder.AddJsonFile("config.json");

            // Add configuration from an optional config.development.json, config.staging.json or 
            // config.production.json file, depending on the environment. These settings override the ones in the 
            // config.json file.
            configurationBuilder.AddJsonFile($"config.{hostingEnvironment.EnvironmentName}.json", optional: true);

            // This reads the configuration keys from the secret store. This allows you to store connection strings
            // and other sensitive settings, so you don't have to check them into your source control provider. See 
            // http://go.microsoft.com/fwlink/?LinkID=532709 and
            // http://docs.asp.net/en/latest/security/app-secrets.html
            configurationBuilder.AddUserSecrets();

            // Add configuration specific to the Development, Staging or Production environments. This config can 
            // be stored on the machine being deployed to or if you are using Azure, in the cloud. These settings 
            // override the ones in all of the above config files.
            // Note: To set environment variables for debugging navigate to:
            // Project Properties -> Debug Tab -> Environment Variables
            // Note: To get environment variables for the machine use the following command in PowerShell:
            // $env:[VARIABLE_NAME]
            // Note: To set environment variables for the machine use the following command in PowerShell:
            // $env:[VARIABLE_NAME]="[VARIABLE_VALUE]"
            // Note: Environment variables use a colon separator e.g. You can override the site title by creating a 
            // variable named AppSettings:SiteTitle. See 
            // http://docs.asp.net/en/latest/security/app-secrets.html
            configurationBuilder.AddEnvironmentVariables();

            return configurationBuilder.Build();
        }
开发者ID:Pro-Coded,项目名称:Pro.MVCMagic,代码行数:42,代码来源:Startup.Configuration.cs

示例6: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            //Setting up configuration builder
            var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddEnvironmentVariables();

            if (!env.IsProduction())
            {
                builder.AddUserSecrets();
            }
            else
            {

            }

            Configuration = builder.Build();

            //Setting up configuration
            if (!env.IsProduction())
            {
                var confConnectString = Configuration.GetSection("Data:DefaultConnection:ConnectionString");
                confConnectString.Value = @"Server=(localdb)\mssqllocaldb;Database=GetHabitsAspNet5;Trusted_Connection=True;";

                var identityConnection = Configuration.GetSection("Data:IdentityConnection:ConnectionString");
                identityConnection.Value = @"Server=(localdb)\mssqllocaldb;Database=GetHabitsIdentity;Trusted_Connection=True;";
            }
            else
            {

            }
        }
开发者ID:boyarincev,项目名称:GetHabitsAspNet5,代码行数:32,代码来源:Startup.cs

示例7: Startup

        public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            InitializeLogging(loggerFactory);
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json");

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();

            // Uncomment the block of code below if you want to load secrets from KeyVault
            // It is recommended to use certs for all authentication when using KeyVault
//#if NET451
//            var config = builder.Build();
//            builder.AddKeyVaultSecrets(config["AzureAd:ClientId"],
//                config["KeyVault:Name"],
//                config["AzureAd:Asymmetric:CertificateThumbprint"],
//                Convert.ToBoolean(config["AzureAd:Asymmetric:ValidationRequired"]),
//                loggerFactory);
//#endif

            Configuration = builder.Build();
        }
开发者ID:mspnp,项目名称:multitenant-saas-guidance,代码行数:28,代码来源:Startup.cs

示例8: BuildConfig

        private static IConfigurationRoot BuildConfig()
        {
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            if (builder.GetFileProvider().GetFileInfo("project.json")?.Exists == true)
            {
                builder.AddUserSecrets();
            }
            return builder.Build();
        }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:11,代码来源:Startup.cs

示例9: StartupDevelopment

 public StartupDevelopment(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
        // Add the user secrets
         builder.AddUserSecrets();
         Configuration = builder.Build();
 }
开发者ID:jmurkoth,项目名称:TODOMVC,代码行数:11,代码来源:StartupDevelopment.cs

示例10: Startup

 public Startup(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
         .SetBasePath(env.ContentRootPath)
         .AddJsonFile("appsettings.json")
         .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
     if (!env.IsDevelopment())
     {
         builder.AddUserSecrets();
     }
     Configuration = builder.Build();
 }
开发者ID:ebt-techtalk,项目名称:asp.net,代码行数:12,代码来源:Startup.cs

示例11: Startup

        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables();

            builder.AddUserSecrets();

            Configuration = builder.Build();
        }
开发者ID:rdefreitas,项目名称:saaskit,代码行数:12,代码来源:Startup.cs

示例12: Startup

 public Startup(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
         .AddJsonFile("config.json");
     if(env.IsDevelopment())
     {
         // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
         builder.AddUserSecrets();
     }
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
开发者ID:noliar,项目名称:MoreAuthentication,代码行数:12,代码来源:Startup.cs

示例13: Startup

        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("config.json");

            if (env.IsDevelopment())
            {
                builder.AddUserSecrets();
            }

            _config = builder.Build();
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:13,代码来源:Startup.cs

示例14: Startup

        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:oshalygin,项目名称:SolutionPub,代码行数:13,代码来源:Startup.cs

示例15: Startup

        /// <summary>
        /// 1. Loads configurations
        /// </summary>
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder();

            // general config file
            builder.AddJsonFile("config.json");
            // environment-specific config
            builder.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
            // sensitive information config
            if (env.IsDevelopment()) builder.AddUserSecrets();

            Configuration = builder.Build();
        }
开发者ID:obscuredesign,项目名称:web,代码行数:16,代码来源:Startup.cs


注:本文中的Microsoft.Extensions.Configuration.ConfigurationBuilder.AddUserSecrets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。