Skip to content

Commit cddebc5

Browse files
authored
App Config + Key Vault sample (Azure#22815)
Resolves Azure#21800
1 parent cb240f3 commit cddebc5

24 files changed

+1259
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vs/
2+
bin/
3+
obj/
4+
*.user
5+
launchSettings.json
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<RootNamespace>AppSecretsConfig</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Azure.Identity" Version="1.4.0" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="4.4.0" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.AspNetCore.Mvc.RazorPages;
11+
using Microsoft.Extensions.Logging;
12+
13+
namespace AppSecretsConfig.Pages
14+
{
15+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
16+
public class ErrorModel : PageModel
17+
{
18+
public string RequestId { get; set; }
19+
20+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
21+
22+
private readonly ILogger<ErrorModel> _logger;
23+
24+
public ErrorModel(ILogger<ErrorModel> logger)
25+
{
26+
_logger = logger;
27+
}
28+
29+
public void OnGet()
30+
{
31+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
32+
}
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@page
2+
@model IndexModel
3+
4+
@using Microsoft.Extensions.Configuration
5+
@inject IConfiguration Configuration
6+
7+
@{
8+
ViewData["Title"] = "Home page";
9+
}
10+
11+
<div class="text-center p-3">
12+
<p class="text-left">
13+
The key-value pairs shown below are enumerated from <a href="https://docs.microsoft.com/azure/azure-app-configuration/overview">Azure App Configuration</a>.
14+
You can store non-secret values e.g., endpoint host names and application IDs directly in App Configuration
15+
and secrets e.g., application secrets in <a href="https://docs.microsoft.com/azure/key-vault/general/overview">Azure Key Vault</a> with a reference to those secrets
16+
in App Configuration. The <a href="https://nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration">Microsoft.Extensions.Configuration.AzureAppConfiguration</a>
17+
configuration provider will automatically retrieve secret values when retrieving key-values containing these special references.
18+
</p>
19+
<table class="table text-left">
20+
<thead>
21+
<tr>
22+
<th scope="col">Key</th>
23+
<th scope="col">Value</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<tr>
28+
<td scope="row">APPCONFIG_VALUE</td>
29+
<td>@Configuration["APPCONFIG_VALUE"]</td>
30+
</tr>
31+
<tr>
32+
<td scope="row">KEYVAULT_SECRET</td>
33+
<td>@Configuration["KEYVAULT_SECRET"]</td>
34+
</tr>
35+
</tbody>
36+
37+
</table>
38+
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.AspNetCore.Mvc.RazorPages;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace AppSecretsConfig.Pages
13+
{
14+
public class IndexModel : PageModel
15+
{
16+
private readonly ILogger<IndexModel> _logger;
17+
18+
public IndexModel(ILogger<IndexModel> logger)
19+
{
20+
_logger = logger;
21+
}
22+
23+
public void OnGet()
24+
{
25+
}
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - AppConfigSample</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" />
9+
</head>
10+
<body>
11+
<div class="container">
12+
<main role="main" class="pb-3">
13+
@RenderBody()
14+
</main>
15+
</div>
16+
17+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
18+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
19+
<script src="~/js/site.js" asp-append-version="true"></script>
20+
21+
@RenderSection("Scripts", required: false)
22+
</body>
23+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@using AppSecretsConfig
2+
@namespace AppSecretsConfig.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}

0 commit comments

Comments
 (0)