Let's carry out the following steps to deploy our backend to production:
- In Solution Explorer, right-click on the QandA project and select Publish....
- The Publish screen opens. Select the Publish section and then click the Start button:
- We are then prompted to choose a publish target. Choose Create New and click the Create Profile button:
- The next step is to specify our Microsoft account and name the production app service. Note down the name you choose because we'll eventually reference this in the frontend project:
- We can also create a SQL database on this screen. Let's do this by clicking the Create a SQL Database option.
- In the dialog that opens, enter the database name to match what we have specified in the connection string in the appsettings.Production.json file.
- We need to create a new database server, so click the New... option to the right of the Database server field.
- Let's use the server name and credentials we specified in the connection string in the appsettings.Production.json file.
- Click the OK button to confirm the server details and then the OK button on the database screen beneath it.
- We are taken back to the Azure App Service dialog with the details that we have just specified in the bottom-right corner.
- Click the Create button to create the services in Azure. This will take a few minutes to complete.
Notice the warning at the bottom of the screen:
This is a reminder that there is a SignalR Service in Azure that we could use for our real-time API. Implementing this is beyond the scope of this chapter, so we'll continue to use the real-time API within our app service.
- We can then publish our code to the Azure services by clicking the Publish button. Again, this will take a few minutes to complete.
- Just before deployment is complete, the following prompt may appear:
Choose Yes to turn web sockets on in our app service.
- Eventually, a browser window will open containing the path to our deployed backend. Add /api/questions to the path in the browser:
We will see the default questions from our database. Congratulations! We have just deployed our first SQL database and ASP.NET Core app in Azure!
- Let's go to the Azure portal by navigating to https://portal.azure.com. Select the All resources option:
As expected, we see the services that we have just provisioned.
Excellent! We have just successfully deployed our backend in Azure!