/// <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();
        }
Ejemplo n.º 2
0
 public Startup()
 {
     var builder = new ConfigurationBuilder()
         .AddJsonFile("appsettings.json");
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
Ejemplo n.º 3
0
        // 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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        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>();
        }
Ejemplo n.º 8
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddJsonFile($"setup.json", optional: true, reloadOnChange: true);


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

            var threadCountInString = Configuration.GetSection("ThreadCount").Value;

            var threadCount = threadCountInString != null?Convert.ToInt32(threadCountInString) : 200;

            ThreadPool.SetMinThreads(threadCount, threadCount);

            Env = env;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        public Startup(IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 11
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 12
0
        public Startup(IApplicationEnvironment env)
        {
            var builder = new ConfigurationBuilder();
            builder.SetBasePath(env.ApplicationBasePath);
            builder.AddEnvironmentVariables();

            Configuration = builder.Build();
        }
Ejemplo n.º 13
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build().ReloadOnChanged("appsettings.json");
        }
Ejemplo n.º 14
0
        public void Register(IServiceCollection serviceCollection)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            builder.AddEnvironmentVariables();

            serviceCollection.AddInstance<IConfiguration>(builder.Build());
        }
Ejemplo n.º 15
0
 public Startup(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
         .AddJsonFile("appsettings.json")
         .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
Ejemplo n.º 16
0
Archivo: Startup.cs Proyecto: tams89/CV
        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder();

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 17
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder()    //appEnv.ApplicationBasePath
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 18
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     // Setup configuration sources.
     var builder = new ConfigurationBuilder()
         .SetBasePath(appEnv.ApplicationBasePath);
                 
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
 }
Ejemplo n.º 19
0
        public TestStartup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
        public Startup(IHostingEnvironment env)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), false, true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 21
0
        private static IConfiguration ConfigureConfiguration(IHostingEnvironment hostingEnvironment)
        {
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.SetBasePath(hostingEnvironment.ContentRootPath);
            configurationBuilder.AddJsonFile("config.json", optional: true);
            configurationBuilder.AddEnvironmentVariables();

            return configurationBuilder.Build();
        }
 public RecaptchaTagHelper() : base()
 {
     var builder = new ConfigurationBuilder();
     builder.AddJsonFile("appsettings.json");
     builder.AddEnvironmentVariables();
     var config = builder.Build();
     secret = config["RecaptchaOptions:Secret"];
     siteKey = config["RecaptchaOptions:SiteKey"];
 }
Ejemplo n.º 23
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            var builder = new ConfigurationBuilder()
                   .AddJsonFile("appsettings.json")
                   .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
            Configuration["Data:DefaultConnection:ConnectionString"] = $@"Data Source={appEnv.ApplicationBasePath}/Heroes.db";
        }
Ejemplo n.º 24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var builder = new ConfigurationBuilder()
                .AddJsonFile("config.json");
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            services.AddOptions();
            services.ConfigureOptions<Settings>(); // errors here!
        }
Ejemplo n.º 25
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", true, true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 26
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                           .AddJsonFile("config.json", optional: true);
            builder.AddEnvironmentVariables();

            Configuration = builder.Build();

        }
Ejemplo n.º 27
0
        public Startup(IHostingEnvironment env)
        {
            // Set up configuration providers.
            var builder = new ConfigurationBuilder()
				.SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 28
0
        internal AuthenticationRun(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
               .SetBasePath(env.ContentRootPath)
               .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
               .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
            SetUp();
        }
Ejemplo n.º 29
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Set up configuration sources.
	        var builder = new ConfigurationBuilder()
				.SetBasePath(appEnv.ApplicationBasePath)
		        .AddJsonFile("appsettings.json")
		        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

			builder.AddEnvironmentVariables();
			Configuration = builder.Build();
        }
Ejemplo n.º 30
0
 public Startup(IHostingEnvironment env)
 {
     var builder = new ConfigurationBuilder()
         .SetBasePath(env.ContentRootPath)
         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
         .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
     builder.AddEnvironmentVariables();
     Configuration = builder.Build();
     //初始化映射关系
     FonourMapper.Initialize();
 }
Ejemplo n.º 31
0
 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();
 }
Ejemplo n.º 32
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

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

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
            _env          = env;
        }
Ejemplo n.º 33
0
        private IConfiguration SetupConfiguration()
        {
            var existingConfiguration = Builder.Services.First(z => z.ServiceType == typeof(IConfiguration))
                                        .ImplementationInstance as IConfiguration;

            var configurationBuilder = new MsftConfigurationBinder();

            configurationBuilder.AddConfiguration(existingConfiguration);

            configurationBuilder
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{_environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
            .AddYamlFile($"appsettings.{_environment.EnvironmentName}.yml", optional: true, reloadOnChange: true);

            var cb = new ConfigurationBuilder(
                Scanner,
                _environment,
                existingConfiguration,
                configurationBuilder,
                _logger,
                Properties);

            cb.Build();

            if (_environment.IsDevelopment() && !string.IsNullOrEmpty(_environment.ApplicationName))
            {
                var appAssembly = Assembly.Load(new AssemblyName(_environment.ApplicationName));
                if (appAssembly != null)
                {
                    configurationBuilder.AddUserSecrets(appAssembly, optional: true);
                }
            }

            configurationBuilder.AddEnvironmentVariables();

            var newConfig = configurationBuilder.Build();

            Builder.Services.Replace(ServiceDescriptor.Singleton <IConfiguration>(newConfig));
            return(newConfig);
        }
Ejemplo n.º 34
0
        public static IConfigurationRoot BuildConfiguration(
            AbpConfigurationBuilderOptions options = null)
        {
            options = options ?? new AbpConfigurationBuilderOptions();

            if (options.BasePath.IsNullOrEmpty())
            {
                options.BasePath = Directory.GetCurrentDirectory();
            }

            var builder = new ConfigurationBuilder()
                          .SetBasePath(options.BasePath)
                          .AddJsonFile(options.FileName + ".json", optional: true, reloadOnChange: true);

            if (!options.EnvironmentName.IsNullOrEmpty())
            {
                builder = builder.AddJsonFile($"{options.FileName}.{options.EnvironmentName}.json", optional: true, reloadOnChange: true);
            }

            if (options.EnvironmentName == "Development")
            {
                if (options.UserSecretsId != null)
                {
                    builder.AddUserSecrets(options.UserSecretsId);
                }
                else if (options.UserSecretsAssembly != null)
                {
                    builder.AddUserSecrets(options.UserSecretsAssembly, true);
                }
            }

            builder = builder.AddEnvironmentVariables(options.EnvironmentVariablesPrefix);

            if (options.CommandLineArgs != null)
            {
                builder = builder.AddCommandLine(options.CommandLineArgs);
            }

            return(builder.Build());
        }
Ejemplo n.º 35
0
        private IConfiguration SetupConfiguration()
        {
            var currentDirectory = Environment.GetEnvironmentVariable("AzureWebJobsScriptRoot") ?? "/home/site/wwwroot";
            var isLocal          = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")) &&
                                   !Directory.Exists(currentDirectory);

            if (isLocal)
            {
                currentDirectory = Environment.CurrentDirectory;
            }

            var existingConfiguration = Builder.Services.First(z => z.ServiceType == typeof(IConfiguration))
                                        .ImplementationInstance as IConfiguration;

            var configurationOptions = this.GetOrAdd(() => new ConfigurationOptions());

            var configurationBuilder = new MsftConfigurationBuilder()
                                       .SetBasePath(currentDirectory)
                                       .AddConfiguration(existingConfiguration)
                                       .Apply(configurationOptions.ApplicationConfiguration)
                                       .Apply(configurationOptions.EnvironmentConfiguration, _environment.EnvironmentName)
                                       .Apply(configurationOptions.EnvironmentConfiguration, "local");

            if (_environment.IsDevelopment())
            {
                configurationBuilder.AddUserSecrets(FunctionsAssembly, true);
            }

            configurationBuilder
            .AddEnvironmentVariables("RSG_")
            .AddEnvironmentVariables();

            IConfigurationSource?source = null;

            foreach (var item in configurationBuilder.Sources.Reverse())
            {
                if ((item is EnvironmentVariablesConfigurationSource env && (string.IsNullOrWhiteSpace(env.Prefix) ||
                                                                             string.Equals(env.Prefix, "RSG_", StringComparison.OrdinalIgnoreCase))) ||
                    (item is JsonConfigurationSource a && string.Equals(
                         a.Path,
                         "secrets.json",
                         StringComparison.OrdinalIgnoreCase
                         )))
                {
                    continue;
                }

                source = item;
                break;
            }

            var index = source == null
                ? configurationBuilder.Sources.Count - 1
                : configurationBuilder.Sources.IndexOf(source);

            var cb = new ConfigurationBuilder(
                Scanner,
                _environment,
                new MsftConfigurationBuilder().AddConfiguration(existingConfiguration !)
                .AddConfiguration(configurationBuilder.Build()).Build(),
                configurationBuilder,
                _logger,
                Properties
                );

            configurationBuilder.Sources.Insert(
                index + 1,
                new ChainedConfigurationSource
            {
                Configuration = cb.Build()
            }
                );

            var newConfig = configurationBuilder.Build();

            Builder.Services.Replace(ServiceDescriptor.Singleton <IConfiguration>(newConfig));
            return(newConfig);
        }