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


C# ConfigurationBuilder.AddEnvironmentVariables方法代码示例

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


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

示例1: 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

示例2: 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

示例3: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // Configuration
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            builder.Build();

            // Logging
            loggerFactory.AddDebug(minLevel: LogLevel.Verbose);
            
            // Using different environments
            if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { }

            // Middlewares
            app.UseDeveloperExceptionPage();
            app.UseRuntimeInfoPage(); // default path is /runtimeinfo            
            app.UseDefaultFiles();
            app.UseStaticFiles();

            // Web sockets
            app.Map("/Managed", (appBuilder) => WebSocketsHelper.Configure(appBuilder, loggerFactory));

            // IIS
            app.UseIISPlatformHandler();
        }
开发者ID:streamcode9,项目名称:chat,代码行数:29,代码来源:Startup.cs

示例4: Startup

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


#if DEBUG
            URLS.Api_url = "http://localhost:58517/";
            URLS.Html_url = "http://localhost:7079/oauth.html";
            URLS.Idt_url = "http://localhost:58058/";
            URLS.Mvc_url = "http://localhost:7079/signin-oidc";
#endif

#if RELEASE
            

            URLS.Api_url = "http://it4govwebapi.azurewebsites.net/";
            URLS.Html_url = "http://it4govwebapp.azurewebsites.net/oauth.html";
            URLS.Idt_url = "http://it4govidentityserver.azurewebsites.net";
            URLS.Mvc_url = "http://it4govwebapp.azurewebsites.net/signin-oidc";
#endif

            
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            

            builder.AddEnvironmentVariables();
            Configuration = builder.Build().ReloadOnChanged("appsettings.json");
        }
开发者ID:Charmatzis,项目名称:IT4GOV,代码行数:31,代码来源:Startup.cs

示例5: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            // add the config file which stores the connection string
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json");
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            // add entity framework using the config connection string
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            // add identity: note the AddOpenIddictCore call
            services.AddIdentity<ApplicationUser, ApplicationRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders()
                .AddOpenIddictCore<Application>(config => config.UseEntityFramework());

            // assuming you have an api...
            services.AddMvc();

            // for seeding the database with the demo user details
            services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
            services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>();
        }
开发者ID:chrisjmccrum,项目名称:openiddict-test,代码行数:27,代码来源:Startup.cs

示例6: 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

示例7: 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

示例8: Startup

 public Startup()
 {
     var builder = new ConfigurationBuilder()
         .AddJsonFile("appsettings.json");
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
开发者ID:jmk22,项目名称:SimpleAuthentication03,代码行数:7,代码来源:Startup.cs

示例9: Register

        public void Register(IServiceCollection serviceCollection)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            builder.AddEnvironmentVariables();

            serviceCollection.AddInstance<IConfiguration>(builder.Build());
        }
开发者ID:skimur,项目名称:skimur,代码行数:8,代码来源:Program.cs

示例10: Startup

        public Startup(IApplicationEnvironment env)
        {
            var builder = new ConfigurationBuilder();
            builder.SetBasePath(env.ApplicationBasePath);
            builder.AddEnvironmentVariables();

            Configuration = builder.Build();
        }
开发者ID:iteam-software,项目名称:iteamnm-com,代码行数:8,代码来源:Startup.cs

示例11: Startup

        public Startup(IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:gwartnes,项目名称:Blogness,代码行数:8,代码来源:Startup.cs

示例12: Startup

        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder();

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:tams89,项目名称:CV,代码行数:8,代码来源:Startup.cs

示例13: Startup

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

            builder.AddEnvironmentVariables();
            Configuration = builder.Build().ReloadOnChanged("appsettings.json");
        }
开发者ID:gitter-badger,项目名称:QueueDodge,代码行数:8,代码来源:Startup.cs

示例14: Startup

 public Startup(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
         .AddJsonFile("appsettings.json")
         .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
开发者ID:llenroc,项目名称:asp.net5-auth,代码行数:8,代码来源:Startup.cs

示例15: Startup

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

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
开发者ID:cjqian,项目名称:AspNetAuthorizationWorkshop,代码行数:8,代码来源:Startup.cs


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