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
Copy file name to clipboardExpand all lines: articles/app-service/configure-language-python.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ Existing web applications can be redeployed to Azure as follows:
115
115
116
116
1. **Continuous deployment**: Set up continuous deployment from GitHub Actions, Bitbucket, or Azure Repos as described in the article [Continuous deployment to Azure App Service](deploy-continuous-deployment.md). Or, set up continuous deployment from Local Git as described in the article [Local Git deployment to Azure App Service](deploy-local-git.md).
117
117
118
-
1. **Custom actions**: To perform actions within the App Service container that hosts your app, such as Django database migrations, you can [connect to the container through SSH](configure-linux-open-ssh-session.md). For an example of running Django database migrations, see [Tutorial: Deploy a Django web app with PostgreSQL - generate database schema](tutorial-python-postgresql-app-django.md#4-generate-database-schema).
118
+
1. **Custom actions**: To perform actions within the App Service container that hosts your app, such as Django database migrations, you can [connect to the container through SSH](configure-linux-open-ssh-session.md). For an example of running Django database migrations, see [Tutorial: Deploy a Django web app with PostgreSQL - generate database schema](tutorial-python-postgresql-app-django.md#5-generate-database-schema).
119
119
- When using continuous deployment, you can perform those actions using post-build commands as described earlier under [Customize build automation](#customize-build-automation).
120
120
121
121
With these steps completed, you should be able to commit changes to your source repository and have those updates automatically deployed to App Service.
Copy file name to clipboardExpand all lines: articles/app-service/tutorial-dotnetcore-sqldb-app.md
+43-33Lines changed: 43 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
title: Deploy ASP.NET Core and Azure SQL Database app
4
4
description: Learn how to deploy an ASP.NET Core web app to Azure App Service and connect to an Azure SQL Database.
5
5
ms.topic: tutorial
6
-
ms.date: 09/06/2024
6
+
ms.date: 01/31/2025
7
7
author: cephalin
8
8
ms.author: cephalin
9
9
ms.devlang: csharp
@@ -44,7 +44,7 @@ In this tutorial, you learn how to:
44
44
45
45
::: zone pivot="azure-developer-cli"
46
46
47
-
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free/java).
47
+
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free).
48
48
*[Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) installed. You can follow the steps with the [Azure Cloud Shell](https://shell.azure.com) because it already has Azure Developer CLI installed.
49
49
* Knowledge of ASP.NET Core development.
50
50
***(Optional)** To try GitHub Copilot, a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
@@ -53,7 +53,7 @@ In this tutorial, you learn how to:
53
53
54
54
## Skip to the end
55
55
56
-
You can quickly deploy the sample app in this tutorial and see it running in Azure. Just run the following commands in the [Azure Cloud Shell](https://shell.azure.com), and follow the prompt:
56
+
If you just want to see the sample app in this tutorial running in Azure, just run the following commands in the [Azure Cloud Shell](https://shell.azure.com), and follow the prompt:
57
57
58
58
```bash
59
59
dotnet tool install --global dotnet-ef
@@ -176,47 +176,44 @@ Sign in to the [Azure portal](https://portal.azure.com/) and follow these steps
176
176
177
177
## 3. Secure connection secrets
178
178
179
-
The creation wizard generated the connectivity string for you already as [.NET connection strings](configure-common.md#configure-connection-strings) and [app settings](configure-common.md#configure-app-settings). However, the security best practice is to keep secrets out of App Service completely. You'll move your secrets to a key vault and change your app setting to [Key Vault references](app-service-key-vault-references.md) with the help of Service Connectors.
179
+
The creation wizard generated the connectivity variable for you already as [.NET connection strings](configure-common.md#configure-connection-strings) and [app settings](configure-common.md#configure-app-settings). However, the security best practice is to keep secrets out of App Service completely. You'll move your secrets to a key vault and change your app setting to [Key Vault references](app-service-key-vault-references.md) with the help of Service Connectors.
180
180
181
181
> [!TIP]
182
182
> To use passwordless authentication, see [How do I change the SQL Database connection to use a managed identity instead?](#how-do-i-change-the-sql-database-connection-to-use-a-managed-identity-instead)
183
183
184
184
:::row:::
185
185
:::column span="2":::
186
-
**Step 1:** In the App Service page:
187
-
1. In the left menu, select **Settings > Environment variables > Connection strings**.
186
+
**Step 1: Retrieve the existing connection string**
187
+
1. In the left menu of the App Service page, select **Settings > Environment variables > Connection strings**.
188
188
1. Select **AZURE_SQL_CONNECTIONSTRING**.
189
189
1. In **Add/Edit connection string**, in the **Value** field, find the *Password=* part at the end of the string.
190
190
1. Copy the password string after *Password=* for use later.
191
-
This connection string lets you connect to the SQL database secured behind a private endpoint. The password is saved directly in the App Service app, which isn't the best. Likewise, the Redis cache connection string in the **App settings** tab contains a secret. You'll change this.
191
+
This connection string lets you connect to the SQL database secured behind a private endpoint. However, the secrets are saved directly in the App Service app, which isn't the best. Likewise, the Redis cache connection string in the **App settings** tab contains a secret. You'll change this.
192
192
:::column-end:::
193
193
:::column:::
194
194
:::image type="content" source="./media/tutorial-dotnetcore-sqldb-app/azure-portal-secure-connection-secrets-1.png" alt-text="A screenshot showing how to see the value of an app setting." lightbox="./media/tutorial-dotnetcore-sqldb-app/azure-portal-secure-connection-secrets-1.png":::
195
195
:::column-end:::
196
196
:::row-end:::
197
197
:::row:::
198
198
:::column span="2":::
199
-
**Step 2:**Create a key vault for secure management of secrets.
199
+
**Step 2:Create a key vault for secure management of secrets**
200
200
1. In the top search bar, type "*key vault*", then select **Marketplace** > **Key Vault**.
201
201
1. In **Resource Group**, select **msdocs-core-sql-tutorial**.
202
202
1. In **Key vault name**, type a name that consists of only letters and numbers.
203
-
1. In **Region**, set it to the sample location as the resource group.
203
+
1. In **Region**, set it to the same location as the resource group.
204
204
:::column-end:::
205
205
:::column:::
206
206
:::image type="content" source="./media/tutorial-dotnetcore-sqldb-app/azure-portal-secure-connection-secrets-2.png" alt-text="A screenshot showing how to create a key vault." lightbox="./media/tutorial-dotnetcore-sqldb-app/azure-portal-secure-connection-secrets-2.png":::
207
207
:::column-end:::
208
208
:::row-end:::
209
209
:::row:::
210
210
:::column span="2":::
211
-
**Step 3:**
211
+
**Step 3: Secure the key vault with a Private Endpoint**
212
212
1. Select the **Networking** tab.
213
213
1. Unselect **Enable public access**.
214
214
1. Select **Create a private endpoint**.
215
215
1. In **Resource Group**, select **msdocs-core-sql-tutorial**.
216
-
1. In **Key vault name**, type a name that consists of only letters and numbers.
217
-
1. In **Region**, set it to the sample location as the resource group.
218
216
1. In the dialog, in **Location**, select the same location as your App Service app.
219
-
1. In **Resource Group**, select **msdocs-core-sql-tutorial**.
220
217
1. In **Name**, type **msdocs-core-sql-XYZVvaultEndpoint**.
221
218
1. In **Virtual network**, select **msdocs-core-sql-XYZVnet**.
222
219
1. In **Subnet**, **msdocs-core-sql-XYZSubnet**.
@@ -245,9 +242,9 @@ The creation wizard generated the connectivity string for you already as [.NET c
245
242
:::row-end:::
246
243
:::row:::
247
244
:::column span="2":::
248
-
**Step 5:** In the **Create connection** dialog for the Key Vault connection:
249
-
1. In **Key Vault**, select the key vault you created earlier.
250
-
1. Select **Review + Create**. You should see that **System assigned managed identity** is set to **Selected**.
245
+
**Step 5: Establish the Key Vault connection**
246
+
1. In the **Create connection** dialog for the Key Vault connection, in **Key Vault**, select the key vault you created earlier.
247
+
1. Select **Review + Create**.
251
248
1. When validation completes, select **Create**.
252
249
:::column-end:::
253
250
:::column:::
@@ -256,10 +253,9 @@ The creation wizard generated the connectivity string for you already as [.NET c
256
253
:::row-end:::
257
254
:::row:::
258
255
:::column span="2":::
259
-
**Step 6:** You're back in the edit dialog for **defaultConnector**.
260
-
1. In the **Authentication** tab, wait for the key vault connector to be created. When it's finished, the **Key Vault Connection** dropdown automatically selects it.
256
+
**Step 6: Finalize the SQL Database connector settings**
257
+
1. You're back in the edit dialog for **defaultConnector**. In the **Authentication** tab, wait for the key vault connector to be created. When it's finished, the **Key Vault Connection** dropdown automatically selects it.
261
258
1. Select **Next: Networking**.
262
-
1. Select **Configure firewall rules to enable access to target service**. The app creation wizard already secured the SQL database with a private endpoint.
263
259
1. Select **Save**. Wait until the **Update succeeded** notification appears.
264
260
:::column-end:::
265
261
:::column:::
@@ -268,8 +264,8 @@ The creation wizard generated the connectivity string for you already as [.NET c
268
264
:::row-end:::
269
265
:::row:::
270
266
:::column span="2":::
271
-
**Step 7:** In the Service Connectors page:
272
-
1. Select checkbox next to the Cache for Redis connector, then select **Edit**.
267
+
**Step 7: Configure the Redis connector to use Key Vault secrets**
268
+
1. In the Service Connectors page, select the checkbox next to the Cache for Redis connector, then select **Edit**.
273
269
1. Select the **Authentication** tab.
274
270
1. Select **Store Secret in Key Vault**.
275
271
1. Under **Key Vault Connection**, select the key vault you created.
@@ -283,8 +279,8 @@ The creation wizard generated the connectivity string for you already as [.NET c
283
279
:::row-end:::
284
280
:::row:::
285
281
:::column span="2":::
286
-
**Step 8:** To verify your changes:
287
-
1. From the left menu, select **Environment variables > Connection strings** again.
282
+
**Step 8: Verify the Key Vault integration**
283
+
1. From the left menu, select **Settings > Environment variables > Connection strings** again.
288
284
1. Next to **AZURE_SQL_CONNECTIONSTRING**, select **Show value**. The value should be `@Microsoft.KeyVault(...)`, which means that it's a [key vault reference](app-service-key-vault-references.md) because the secret is now managed in the key vault.
289
285
1. To verify the Redis connection string, select the **App setting** tab. Next to **AZURE_REDIS_CONNECTIONSTRING**, select **Show value**. The value should be `@Microsoft.KeyVault(...)` too.
290
286
:::column-end:::
@@ -293,6 +289,13 @@ The creation wizard generated the connectivity string for you already as [.NET c
293
289
:::column-end:::
294
290
:::row-end:::
295
291
292
+
To summarize, the process for securing your connection secrets involved:
293
+
294
+
- Retrieving the connection secrets from the App Service app's environment variables.
295
+
- Creating a key vault.
296
+
- Creating a Key Vault connection with the system-assigned managed identity.
297
+
- Updating the service connectors to store the secrets in the key vault.
298
+
296
299
## 4. Deploy sample code
297
300
298
301
In this step, you configure GitHub deployment using GitHub Actions. It's just one of many ways to deploy to App Service, but also a great way to have continuous integration in your deployment process. By default, every `git push` to your GitHub repository kicks off the build and deploy action.
@@ -412,21 +415,25 @@ In this step, you configure GitHub deployment using GitHub Actions. It's just on
412
415
:::column-end:::
413
416
:::row-end:::
414
417
418
+
Having issues? Check the [Troubleshooting section](#troubleshooting).
419
+
415
420
## 5. Generate database schema
416
421
417
-
With the SQL Database protected by the virtual network, the easiest way to run [dotnet database migrations](/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli) is in an SSH session with the App Service container.
422
+
With the SQL Database protected by the virtual network, the easiest way to run [dotnet database migrations](/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli) is in an SSH session with the Linux container in App Service.
418
423
419
424
:::row:::
420
425
:::column span="2":::
421
-
**Step 1:** Back in the App Service page, in the left menu, select **Development Tools** > **SSH**, then select **Go**.
426
+
**Step 1:** Back in the App Service page, in the left menu,
427
+
1. Select **Development Tools** > **SSH**.
428
+
1. Select **Go**.
422
429
:::column-end:::
423
430
:::column:::
424
431
:::image type="content" source="./media/tutorial-dotnetcore-sqldb-app/azure-portal-generate-db-schema-1.png" alt-text="A screenshot showing how to open the SSH shell for your app from the Azure portal." lightbox="./media/tutorial-dotnetcore-sqldb-app/azure-portal-generate-db-schema-1.png":::
425
432
:::column-end:::
426
433
:::row-end:::
427
434
:::row:::
428
435
:::column span="2":::
429
-
**Step 2:** In the SSH terminal:
436
+
**Step 2:** In the SSH session:
430
437
1. Run `cd /home/site/wwwroot`. Here are all your deployed files.
431
438
1. Run the migration bundle that the GitHub workflow generated, with the command `./migrationsbundle -- --environment Production`. If it succeeds, App Service is connecting successfully to the SQL Database. Remember that `--environment Production` corresponds to the code changes you made in *Program.cs*.
432
439
:::column-end:::
@@ -454,7 +461,7 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
454
461
:::row:::
455
462
:::column span="2":::
456
463
**Step 2:** Add a few tasks to the list.
457
-
Congratulations, you're running a secure data-driven ASP.NET Core app in Azure App Service.
464
+
Congratulations, you're running a web app in Azure App Service, with secure connectivity to Azure SQL Database.
458
465
:::column-end:::
459
466
:::column:::
460
467
:::image type="content" source="./media/tutorial-dotnetcore-sqldb-app/azure-portal-browse-app-2.png" alt-text="A screenshot of the .NET Core app running in App Service." lightbox="./media/tutorial-dotnetcore-sqldb-app/azure-portal-browse-app-2.png":::
@@ -466,13 +473,14 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
466
473
467
474
## 7. Stream diagnostic logs
468
475
469
-
Azure App Service captures all messages logged to the console to assist you in diagnosing issues with your application. The sample app outputs console log messages in each of its endpoints to demonstrate this capability.
476
+
Azure App Service captures all console logs to help you diagnose issues with your application. The sample app includes logging code in each of its endpoints to demonstrate this capability.
470
477
471
478
:::row:::
472
479
:::column span="2":::
473
480
**Step 1:** In the App Service page:
474
481
1. From the left menu, select **Monitoring** > **App Service logs**.
475
-
1. Under **Application logging**, select **File System**, then select **Save**.
482
+
1. Under **Application logging**, select **File System**.
483
+
1. In the top menu, select **Save**.
476
484
:::column-end:::
477
485
:::column:::
478
486
:::image type="content" source="./media/tutorial-dotnetcore-sqldb-app/azure-portal-stream-diagnostic-logs-1.png" alt-text="A screenshot showing how to enable native logs in App Service in the Azure portal." lightbox="./media/tutorial-dotnetcore-sqldb-app/azure-portal-stream-diagnostic-logs-1.png":::
@@ -659,13 +667,13 @@ With the SQL Database protected by the virtual network, the easiest way to run d
659
667
azd up
660
668
```
661
669
662
-
1. In the azd output, find the URL for the SSH session and navigate to it in the browser. It looks like this in the output:
670
+
1. In the AZD output, find the URL for the SSH session and navigate to it in the browser. It looks like this in the output:
663
671
664
672
<pre>
665
-
Open SSH session to App Service container at: https://<app-name>-<hash>.scm.azurewebsites.net/webssh/host
673
+
Open SSH session to App Service container at: https://<app-name>.scm.azurewebsites.net/webssh/host
666
674
</pre>
667
675
668
-
1. In the SSH terminal, run the following commands:
676
+
1. In the SSH session, run the following commands:
669
677
670
678
```bash
671
679
cd /home/site/wwwroot
@@ -674,7 +682,9 @@ With the SQL Database protected by the virtual network, the easiest way to run d
674
682
675
683
If it succeeds, App Service is connecting successfully to the database. Remember that `--environment Production` corresponds to the code changes you made in *Program.cs*.
676
684
677
-
In the SSH session, only changes to files in `/home` can persist beyond app restarts. Changes outside of `/home` aren't persisted.
685
+
> [!NOTE]
686
+
> Only changes to files in `/home` can persist beyond app restarts. Changes outside of `/home` aren't persisted.
687
+
>
678
688
679
689
Having issues? Check the [Troubleshooting section](#troubleshooting).
@@ -634,7 +634,7 @@ Pricing for the created resources is as follows:
634
634
The Java SE container in App Service already has network connectivity to Cosmos DB, but doesn't contain any migration tools or other MongoDB tools. You have a few options:
635
635
636
636
- Run database migrations automatically at app start, such as with Hibernate and or Flyway.
637
-
- In the app's [SSH session](configure-language-java-deploy-run.md#linux-troubleshooting-tools), install a migration tool like [Flyway CLI](https://documentation.red-gate.com/fd/command-line-184127404.html), then run the migration script. Remember that the installed tool won't persist after an app restart unless it's in the */home* directory.
637
+
- In the app's [SSH session](configure-language-java-deploy-run.md#linux-troubleshooting-tools), install a migration tool like Flyway, then run the migration script. Remember that the installed tool won't persist after an app restart unless it's in the */home* directory.
638
638
- [Integrate the Azure cloud shell](../cloud-shell/private-vnet.md) with the virtual network and run database migrations from there.
639
639
640
640
#### How does local app development work with GitHub Actions?
0 commit comments