本文整理汇总了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;
}
示例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;
}
示例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
}
示例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();
}
示例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();
}
示例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
{
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例13: Startup
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("config.json");
if (env.IsDevelopment())
{
builder.AddUserSecrets();
}
_config = builder.Build();
}
示例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();
}
示例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();
}