Application deployment
.NET Core Azure Visual Studio

Deploying a .NET Core Application to Azure

Welcome to today’s post.

In todays blog I will show you how to publish a .NET Core Web Application to Azure that contains a SQL Database.

After your .Net Core web application has reached a stage where it is ready for deployment, it is ready for publication to Azure.

Under your project in Visual Studio right-click and select Publish..

The publish dialog will display as shown:

Note: Before we can publish the application, the following resources in Azure will need to exist:

A resource group (to be created or an existing one selected to contain the web application (App Service).

An Azure SQL Server (to contain the SQL Server Database) An Azure SQL Database (SQL Server, My SQL, Cosmos DB etc.)

Next, click on the Configure link. The following dialog opens:

In the above Connection details, notice the following:

Your web site URL will be of the format:

http://[web app name].azurewebsites.net

Publish credentials will show in the User name and password. Notice the password is totally obscured.

To obtain the publish credentials, you will need to do the following:

Login to Azure.

Go to all resources.

Go to App Service.

Click on Get Publish Profile.

The publish profile in the format [Web App Name].PublishSettings  will be downloaded to your local machine.

Open the file. The publishing credentials will be shown in the keys username and userPWD

Note: Ensure when your source is checked into a repository (TFS, Git etc), that a git ignore includes  extensions .pubxml.user. (Normally VS 2017 will include this file extension by default.) 

Now click on the Settings tab. The following form will show:

Expand the Databases and Entity Framework Migrations chevrons. You will see the following:

The first database connection string corresponds to the connection string during run time in Azure. It will initially contain a local host connection string. To obtain the connection string for the database in Azure, do the following.

Login to Azure.

Go to all resources.

Open the SQL Database.

The database overview shows:

Hover over the Connection Strings property.

Select Copy to Clipboard.

Return to the publish dialog settings.

Paste in the connection string into the edit field for Databases.

The second database connection string corresponds to the connection string during run time for EF Migrations of your database in Azure. It will initially contain a local host connection string. Paste in the connection string to this edit field.

Note: The Azure database connection string will be of the format:

Server=tcp:[SQL Server Name].database.windows.net,1433;Initial Catalog=[Your SQL Database Name];Persist Security Info=False;User ID=[sql server admin login name];Password=[admin password];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

Now save the settings.

In the publish screen hit the publish button and watch your application deploy.

When deployed, the default launch settings will open your Azure web app . It will be of the form:

http://[appname].azurewebsites.net

That’s all!

Thanks for reading this post and hope it has been helpful.

Social media & sharing icons powered by UltimatelySocial