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
*<ahref="https://dotnet.microsoft.com/download/dotnet-core/3.1"target="_blank">Install the latest .NET Core 3.1 SDK</a>
39
39
40
40
## Create local .NET Core app
41
41
@@ -59,8 +59,8 @@ The sample project contains a basic CRUD (create-read-update-delete) app using [
59
59
Run the following commands to install the required packages, run database migrations, and start the application.
60
60
61
61
```bash
62
-
dotnet tool install -g dotnet-ef --version 3.1.1
63
-
dotnet-ef database update
62
+
dotnet tool install -g dotnet-ef
63
+
dotnetef database update
64
64
dotnet run
65
65
```
66
66
@@ -86,25 +86,25 @@ For SQL Database, this tutorial uses [Azure SQL Database](/azure/sql-database/).
86
86
87
87
In the Cloud Shell, create a SQL Database logical server with the [`az sql server create`](/cli/azure/sql/server?view=azure-cli-latest#az-sql-server-create) command.
88
88
89
-
Replace the *\<server_name>* placeholder with a unique SQL Database name. This name is used as the part of the SQL Database endpoint, `<server_name>.database.windows.net`, so the name needs to be unique across all logical servers in Azure. The name must contain only lowercase letters, numbers, and the hyphen (-) character, and must be between 3 and 50 characters long. Also, replace *\<db_username>* and *\<db_password>* with a username and password of your choice.
89
+
Replace the *\<server-name>* placeholder with a *unique* SQL Database name. This name is used as the part of the globally unique SQL Database endpoint, `<server-name>.database.windows.net`. Valid characters are `a`-`z`, `0`-`9`, `-`. Also, replace *\<db-username>* and *\<db-password>* with a username and password of your choice.
90
90
91
91
92
92
```azurecli-interactive
93
-
az sql server create --name <server_name> --resource-group myResourceGroup --location "West Europe" --admin-user <db_username> --admin-password <db_password>
93
+
az sql server create --name <server-name> --resource-group myResourceGroup --location "West Europe" --admin-user <db-username> --admin-password <db-password>
94
94
```
95
95
96
96
When the SQL Database logical server is created, the Azure CLI shows information similar to the following example:
@@ -118,137 +118,158 @@ When the SQL Database logical server is created, the Azure CLI shows information
118
118
Create an [Azure SQL Database server-level firewall rule](../sql-database/sql-database-firewall-configure.md) using the [`az sql server firewall create`](/cli/azure/sql/server/firewall-rule?view=azure-cli-latest#az-sql-server-firewall-rule-create) command. When both starting IP and end IP are set to 0.0.0.0, the firewall is only opened for other Azure resources.
119
119
120
120
```azurecli-interactive
121
-
az sql server firewall-rule create --resource-group myResourceGroup --server <server_name> --name AllowAllIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
121
+
az sql server firewall-rule create --resource-group myResourceGroup --server <server-name> --name AllowAzureIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
122
122
```
123
123
124
124
> [!TIP]
125
125
> You can be even more restrictive in your firewall rule by [using only the outbound IP addresses your app uses](overview-inbound-outbound-ips.md#find-outbound-ips).
126
126
>
127
127
128
+
In the Cloud Shell, run the command again to allow access from your local computer by replacing *\<your-ip-address>* with [your local IPv4 IP address](https://www.whatsmyip.org/).
129
+
130
+
```azurecli-interactive
131
+
az sql server firewall-rule create --name AllowLocalClient --server <mysql_server_name> --resource-group myResourceGroup --start-ip-address=<your-ip-address> --end-ip-address=<your-ip-address>
132
+
```
133
+
128
134
### Create a database
129
135
130
136
Create a database with an [S0 performance level](../sql-database/sql-database-service-tiers-dtu.md) in the server using the [`az sql db create`](/cli/azure/sql/db?view=azure-cli-latest#az-sql-db-create) command.
131
137
132
138
```azurecli-interactive
133
-
az sql db create --resource-group myResourceGroup --server <server_name> --name coreDB --service-objective S0
139
+
az sql db create --resource-group myResourceGroup --server <server-name> --name coreDB --service-objective S0
134
140
```
135
141
136
142
### Create connection string
137
143
138
-
Replace the following string with the *\<server_name>*, *\<db_username>*, and *\<db_password>* you used earlier.
144
+
Get the connection string using the [`az sql db show-connection-string`](/cli/azure/sql/db?view=azure-cli-latest#az-sql-db-show-connection-string) command.
139
145
146
+
```azurecli-interactive
147
+
az sql db show-connection-string --client ado.net --server cephalin-core --name coreDB
> For production apps that need to scale out, follow the best practices in [Applying migrations in production](/aspnet/core/data/ef-rp/migrations#applying-migrations-in-production).
172
+
>
159
173
160
-
[!INCLUDE [Create web app](../../includes/app-service-web-create-web-app-dotnetcore-win-no-h.md)]
174
+
### Run database migrations to the production database
161
175
162
-
### Configure connection string
176
+
Your app currently connects to a local Sqlite database. Now that you configured an Azure SQL Database, recreate the initial migration to target it.
163
177
164
-
To set connection strings for your Azure app, use the [`az webapp config appsettings set`](/cli/azure/webapp/config/appsettings?view=azure-cli-latest#az-webapp-config-appsettings-set) command in the Cloud Shell. In the following command, replace *\<app name>*, as well as the *\<connection_string>* parameter with the connection string you created earlier.
178
+
From the repository root, run the following commands. Replace *\<connection-string>* with the connection string you created earlier.
165
179
166
-
```azurecli-interactive
167
-
az webapp config connection-string set --resource-group myResourceGroup --name <app name> --settings MyDbConnection="<connection_string>" --connection-string-type SQLServer
In ASP.NET Core, you can use this named connection string (`MyDbConnection`) using the standard pattern, like any connection string specified in *appsettings.json*. In this case, `MyDbConnection` is also defined in your *appsettings.json*. When running in App Service, the connection string defined in App Service takes precedence over the connection string defined in your *appsettings.json*. The code uses the *appsettings.json* value during local development, and the same code uses the App Service value when deployed.
198
+
### Run app with new configuration
171
199
172
-
To see how the connection string is referenced in your code, see [Connect to SQL Database in production](#connect-to-sql-database-in-production).
200
+
Now that database migrations is run on the production database, test your app by running:
173
201
174
-
### Configure environment variable
202
+
```
203
+
dotnet run
204
+
```
175
205
176
-
Next, set `ASPNETCORE_ENVIRONMENT` app setting to _Production_. This setting lets you know whether you're running in Azure, because you use SQLite for your local development environment and SQL Database for your Azure environment.
206
+
Navigate to `http://localhost:5000` in a browser. Select the **Create New** link and create a couple _to-do_ items. Your app is now reading and writing data to the production database.
177
207
178
-
The following example configures a `ASPNETCORE_ENVIRONMENT` app setting in your Azure app. Replace the *\<app_name>* placeholder.
208
+
Commit your local changes, then commit it into your Git repository.
179
209
180
-
```azurecli-interactive
181
-
az webapp config appsettings set --name <app_name> --resource-group myResourceGroup --settings ASPNETCORE_ENVIRONMENT="Production"
210
+
```bash
211
+
git add .
212
+
git commit -m "connect to SQLDB in Azure"
182
213
```
183
214
184
-
To see how the environment variable is referenced in your code, see [Connect to SQL Database in production](#connect-to-sql-database-in-production).
215
+
You're now ready to deploy your code.
185
216
186
-
### Connect to SQL Database in production
217
+
##Deploy app to Azure
187
218
188
-
In your local repository, open Startup.cs and find the following code:
219
+
In this step, you deploy your SQL Database-connected .NET Core application to App Service.
If this code detects that it's running in production (which indicates the Azure environment), then it uses the connection string you configured to connect to the SQL Database.
227
+
[!INCLUDE [Create app service plan](../../includes/app-service-web-create-app-service-plan-no-h.md)]
211
228
212
-
The `Database.Migrate()` call helps you when it's run in Azure, because it automatically creates the databases that your .NET Core app needs, based on its migration configuration.
229
+
### Create a web app
213
230
214
-
> [!IMPORTANT]
215
-
> For production apps that need to scale out, follow the best practices in [Applying migrations in production](/aspnet/core/data/ef-rp/migrations#applying-migrations-in-production).
216
-
>
231
+
[!INCLUDE [Create web app](../../includes/app-service-web-create-web-app-dotnetcore-win-no-h.md)]
217
232
218
-
Save your changes, then commit it into your Git repository.
233
+
### Configure connection string
219
234
220
-
```bash
221
-
git add .
222
-
git commit -m "connect to SQLDB in Azure"
235
+
To set connection strings for your Azure app, use the [`az webapp config appsettings set`](/cli/azure/webapp/config/appsettings?view=azure-cli-latest#az-webapp-config-appsettings-set) command in the Cloud Shell. In the following command, replace *\<app-name>*, as well as the *\<connection-string>* parameter with the connection string you created earlier.
236
+
237
+
```azurecli-interactive
238
+
az webapp config connection-string set --resource-group myResourceGroup --name <app-name> --settings MyDbConnection="<connection-string>" --connection-string-type SQLAzure
223
239
```
224
240
241
+
In ASP.NET Core, you can use this named connection string (`MyDbConnection`) using the standard pattern, like any connection string specified in *appsettings.json*. In this case, `MyDbConnection` is also defined in your *appsettings.json*. When running in App Service, the connection string defined in App Service takes precedence over the connection string defined in your *appsettings.json*. The code uses the *appsettings.json* value during local development, and the same code uses the App Service value when deployed.
242
+
243
+
To see how the connection string is referenced in your code, see [Connect to SQL Database in production](#connect-to-sql-database-in-production).
remote: App container will begin restart within 10 seconds.
251
-
To https://<app_name>.scm.azurewebsites.net/<app_name>.git
272
+
To https://<app-name>.scm.azurewebsites.net/<app-name>.git
252
273
* [new branch] master -> master
253
274
</pre>
254
275
@@ -257,7 +278,7 @@ To https://<app_name>.scm.azurewebsites.net/<app_name>.git
257
278
Browse to the deployed app using your web browser.
258
279
259
280
```bash
260
-
http://<app_name>.azurewebsites.net
281
+
http://<app-name>.azurewebsites.net
261
282
```
262
283
263
284
Add a few to-do items.
@@ -278,17 +299,12 @@ Open _Models\Todo.cs_ in the code editor. Add the following property to the `ToD
278
299
publicboolDone { get; set; }
279
300
```
280
301
281
-
### Run Code First Migrations locally
302
+
### Rerun database migrations
282
303
283
-
Run a few commands to make updates to your local database.
304
+
Run a few commands to make updates to the production database.
284
305
285
306
```bash
286
307
dotnet ef migrations add AddProperty
287
-
```
288
-
289
-
Update the local database:
290
-
291
-
```bash
292
308
dotnet ef database update
293
309
```
294
310
@@ -360,7 +376,7 @@ Once the `git push` is complete, navigate to your App Service app and try adding
360
376
361
377

362
378
363
-
All your existing to-do items are still displayed. When you republish your .NET Core app, existing data in your SQL Database isn't lost. Also, Entity Framework Core Migrations only changes the data schema and leaves your existing data intact.
379
+
All your existing to-do items are still displayed. When you republish your ASP.NET Core app, existing data in your SQL Database isn't lost. Also, Entity Framework Core Migrations only changes the data schema and leaves your existing data intact.
364
380
365
381
## Stream diagnostic logs
366
382
@@ -374,7 +390,7 @@ The sample project already follows the guidance at [ASP.NET Core Logging in Azur
374
390
To set the ASP.NET Core [log level](https://docs.microsoft.com/aspnet/core/fundamentals/logging#log-level) in App Service to `Information` from the default level `Error`, use the [`az webapp log config`](/cli/azure/webapp/log?view=azure-cli-latest#az-webapp-log-config) command in the Cloud Shell.
375
391
376
392
```azurecli-interactive
377
-
az webapp log config --name <app_name> --resource-group myResourceGroup --application-logging true --level information
393
+
az webapp log config --name <app-name> --resource-group myResourceGroup --application-logging true --level information
To start log streaming, use the [`az webapp log tail`](/cli/azure/webapp/log?view=azure-cli-latest#az-webapp-log-tail) command in the Cloud Shell.
385
401
386
402
```azurecli-interactive
387
-
az webapp log tail --name <app_name> --resource-group myResourceGroup
403
+
az webapp log tail --name <app-name> --resource-group myResourceGroup
388
404
```
389
405
390
406
Once log streaming has started, refresh the Azure app in the browser to get some web traffic. You can now see console logs piped to the terminal. If you don't see console logs immediately, check again in 30 seconds.
@@ -403,7 +419,7 @@ On the **App Services** page, select the name of your Azure app.
403
419
404
420

405
421
406
-
By default, the portal shows your app's **Overview** page. This page gives you a view of how your app is doing. Here, you can also perform basic management tasks like browse, stop, start, restart, and delete. The left side of the page shows the different configuration pages you can open.
422
+
By default, the portal shows your app's **Overview** page. This page gives you a view of how your app is doing. Here, you can also perform basic management tasks like browse, stop, start, restart, and delete. The tabs on the left side of the page show the different configuration pages you can open.
407
423
408
424

409
425
@@ -425,4 +441,4 @@ What you learned:
425
441
Advance to the next tutorial to learn how to map a custom DNS name to your app.
426
442
427
443
> [!div class="nextstepaction"]
428
-
> [Map an existing custom DNS name to Azure App Service](app-service-web-tutorial-custom-domain.md)
444
+
> [Tutorial: Map custom DNS name to your app](app-service-web-tutorial-custom-domain.md)
0 commit comments