This article will demonstrate how we can deploy or publish an Asp.Net Core 2.0 application on Azure. As we all know once we create an application we have to deploy it on somewhere it can be IIS, Cloud or somewhere else. Publishing or Deploying an application is a bit difficult task and we get so many issues when we don’t know the exact way how to deploy the application.
So, here I am who will let you each step to publish an asp.net core 2.0 on Azure. We have already created an application using Razor Pages, we will use the same application to deploy here.
For more about Razor pages and its fundamentals, See also
- Razor page in Asp.Net Core
- CRUD operations with Asp.Net Core Razor Pages [We will use this application for deployment]
So, let's jump to practical implementation part. We have a project ready for deployment. To publish an Asp.Net Core 2 application, just right click on the project from Solution Explorer and click to “Publish” option. We can see clearly that we are using the “RazorPagesExample” application for publishing which we have created in the previous article and this article is using SQL server database and tables for CRUD operations.
Once we choose “Publish” option it will open a window where we have different options available to publish an app on Azure or another host like IIS, folder etc. Here we have to choose “Microsoft Azure App Service” with “Create New” option and without doing anything else just click to “Publish” Option.
Next window will show the different option to setup hosting environment and its services. Under the “Hosting” section, we can define our application name “App Name”, this name will be used to access the application from the browser, define our subscription plan under which we would like to publish an application and resource group for SQL server.
As we are publishing an application which is performing CRUD operation, so for that we have required to set up the SQL database as well. So, we will directly move to Services option just below to Hosting to create SQL related services like SQL server, SQL database and connection string etc.
As we can see with below screen inside the Services option we have “SQL Database” with Plus [+] sign inside the Resource Type. To create new SQL service, click on PLUS [+] sign.
Once we click to PLUS sign button, it will open a popup window which is responsible for setting up SQL server and database. So, first, we will set up a new SQL Server on Azure. To create new SQL Server on Azure, click to New button as the following screen shown.
From the “Configure SQL Server” window, we have to define SQL Server name, its username and password to access it from SQL Server Management Studio or to use it with Connection String.
After setting up new SQL server and click to OK. It will go back to “Configure SQL Database” screen where we can now set up our SQL database. So here we can define our database name as well as connection string name as we have done with the following screen and click to OK.
So, now we have configured three things, first the plan under which our application will publish on Azure. Second one the SQL server where we have configured our SQL database and tables and last one SQL database under the same SQL server as following screen shows.
Now its time to deploy our application with above configure, so to do that just click to “CREATE” button and it will start deploying our application on Azure as following screen shows.
Here we can see that “Azure Successfully Configured” and Visual Studio is going to publish application on Azure.
It will take few minutes or seconds as per the network connection and speed and deploy an application on Azure and gives us a message as following which says that App has deployed successfully on the following location.
As we all know this application is using SQL database and its tables to perform CRUD operations. We have already created database at the time of configuring SQL services but tables are pending to create. To create required SQL tables under “TestDB” database, to do that we have to access SQL server and its database and manually run the tables scripts.
Now we have to open “Microsoft SQL Server Management Studio” form your system and pass our credentials as we have configured previously for SQL server. Be sure when entering the server name. SQL server name should be in following formats.
Oh, we have a new error, which means we are not able to access defined sql server due to firewall rule with this IP address.
To resolve this error, we have to add this IP address under firewall rules. So, open Microsoft Azure portal and select sql server which we have configured previously.
As of following screen shows, under the SQL Server, we have an option “Firewall/Virtual Networks”. Here we can see with the following screen that we don’t have any IP address defined right now. You have to click to “Add Client IP” to add client IP address under firewall rules and click to save it.
After adding “Client IP Address”, it will come under the Firewall rules. Now we can access this server from SQL Server Management Studio.
If we will try once more to log in with SQL Server Management Studio and able to log in. Now select “TestDB” database which we have configured with this publishment and right click and open a new query window. Here we have to run our sql scripts like create a new table, insert new record etc.
So, finally, we have configured everything including database as well. Now its time to access our deployed application. If we access our application with below URL [This is only for my case, you can be defined your own name]. We will see the application as below.
So, today we have learned how to publish an application created in Asp.Net Core 2.0 on Azure.
I hope this post will help you. Please put your feedback using comment which helps me to improve myself for next post. If you have any doubts please ask your doubts or query in the comment section and If you like this post, please share it with your friends. Thanks