You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Secret Manager stores the secret outside of your project tree, which helps prevent the accidental sharing of secrets within source code. It's used only to test the web app locally. When the app is deployed to Azure like [App Service](../app-service/overview.md), use the *Connection strings*, *Application settings* or environment variables to store the connection string. Alternatively, to avoid connection strings all together, you can [connect to App Configuration using managed identities](./howto-integrate-azure-managed-service-identity.md) or your other [Azure AD identities](./concept-enable-rbac.md).
77
80
78
-
1. Open *Program.cs*, and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
81
+
1. Open *Program.cs*, add the `using TestAppConfig;` statement and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
This code will connect to your App Configuration store using a connection string and load *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
In this example, you'll update a web page to display its content using the settings you configured in your App Configuration store.
122
133
123
-
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
134
+
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
124
135
125
136
```csharp
126
137
namespace TestAppConfig
@@ -138,6 +149,7 @@ In this example, you'll update a web page to display its content using the setti
138
149
1. Bind the `TestApp:Settings` section in configuration to the `Settings` object.
139
150
140
151
#### [.NET 6.x](#tab/core6x)
152
+
141
153
Update *Program.cs* with the following code.
142
154
143
155
```csharp
@@ -154,10 +166,11 @@ In this example, you'll update a web page to display its content using the setti
154
166
// The rest of existing code in program.cs
155
167
// ... ...
156
168
```
157
-
169
+
158
170
#### [.NET Core 3.x](#tab/core3x)
171
+
159
172
Open *Startup.cs* and update the `ConfigureServices` method.
160
-
173
+
161
174
```csharp
162
175
public void ConfigureServices(IServiceCollection services)
163
176
{
@@ -167,11 +180,17 @@ In this example, you'll update a web page to display its content using the setti
1. Open *Index.cshtml.cs* in the *Pages* directory, and update the `IndexModel` class with the following code. Add `using Microsoft.Extensions.Options` namespace at the beginning of the file, if it's not already there.
186
+
1. Open *Index.cshtml.cs* in the *Pages* directory. Add the [Microsoft.Extensions.Options](/dotnet/api/microsoft.extensions.options) namespace and update the `IndexModel` class with the following code.
173
187
174
188
```csharp
189
+
// Existing code in Index.cshtml.cs
190
+
// ... ...
191
+
192
+
using Microsoft.Extensions.Options;
193
+
175
194
public class IndexModel : PageModel
176
195
{
177
196
private readonly ILogger<IndexModel> _logger;
@@ -223,7 +242,7 @@ In this example, you'll update a web page to display its content using the setti
223
242
dotnet run
224
243
```
225
244
226
-
1. Open a browser and navigate to the URL the app is listening on, as specified in the command output. It looks like `https://localhost:5001`.
245
+
1. Open a browser and navigate to the URL the app is listening on, as specified in the command output. It looks like `https://localhost:5001`.
227
246
228
247
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*. When prompted to configure the port for preview, enter *5000*, and select *Open and browse*.
229
248
@@ -248,4 +267,4 @@ In this quickstart, you:
248
267
To learn how to configure your ASP.NET Core web app to dynamically refresh configuration settings, continue to the next tutorial.
0 commit comments