-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update app secrets in development for 3.0 (#16045)
- Loading branch information
1 parent
a64ff86
commit 6d3ed8a
Showing
12 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/Models/MovieSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace UserSecrets.Models | ||
{ | ||
#region snippet_MovieSettingsClass | ||
public class MovieSettings | ||
{ | ||
public string ConnectionString { get; set; } | ||
|
||
public string ServiceApiKey { get; set; } | ||
} | ||
#endregion | ||
} |
22 changes: 22 additions & 0 deletions
22
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace UserSecrets | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
#region snippet_CreateHostBuilder | ||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
#endregion | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace UserSecrets | ||
{ | ||
#region snippet_StartupClass | ||
public class Startup | ||
{ | ||
private string _moviesApiKey = null; | ||
|
||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
_moviesApiKey = Configuration["Movies:ServiceApiKey"]; | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
var result = string.IsNullOrEmpty(_moviesApiKey) ? "Null" : "Not Null"; | ||
await context.Response.WriteAsync($"Secret is {result}"); | ||
}); | ||
} | ||
} | ||
#endregion snippet_StartupClass | ||
} |
51 changes: 51 additions & 0 deletions
51
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/Startup2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace UserSecrets | ||
{ | ||
#region snippet_StartupClass | ||
public class Startup | ||
{ | ||
private string _moviesApiKey = null; | ||
|
||
#region snippet_StartupConstructor | ||
public Startup(IWebHostEnvironment env) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", | ||
optional: false, | ||
reloadOnChange: true) | ||
.AddEnvironmentVariables(); | ||
|
||
if (env.IsDevelopment()) | ||
{ | ||
builder.AddUserSecrets<Startup>(); | ||
} | ||
|
||
Configuration = builder.Build(); | ||
} | ||
#endregion snippet_StartupConstructor | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
_moviesApiKey = Configuration["Movies:ServiceApiKey"]; | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
var result = string.IsNullOrEmpty(_moviesApiKey) ? "Null" : "Not Null"; | ||
await context.Response.WriteAsync($"Secret is {result}"); | ||
}); | ||
} | ||
} | ||
#endregion snippet_StartupClass | ||
} |
10 changes: 10 additions & 0 deletions
10
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/UserSecrets.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- <snippet_CsprojFile> --> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<!-- <snippet_PropertyGroup> --> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<UserSecretsId>79a3edd0-2092-40a2-a04d-dcb46d5ca9ed</UserSecretsId> | ||
</PropertyGroup> | ||
<!-- </snippet_PropertyGroup> --> | ||
</Project> | ||
<!-- </snippet_CsprojFile> --> |
5 changes: 5 additions & 0 deletions
5
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/appsettings-unsecure.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"Movies": "Server=(localdb)\\mssqllocaldb;Database=Movie-1;User Id=johndoe;Password=pass123;MultipleActiveResultSets=true" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
aspnetcore/security/app-secrets/samples/3.x/UserSecrets/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"Movies": "Server=(localdb)\\mssqllocaldb;Database=Movie-1;User Id=johndoe;MultipleActiveResultSets=true" | ||
} | ||
} |