{{announcement.body}}
{{announcement.title}}

How to Publish ASP.NET Core 3.0 Web Apps/APIs in Azure's Linux App Service

DZone 's Guide to

How to Publish ASP.NET Core 3.0 Web Apps/APIs in Azure's Linux App Service

Get your application up and running with Azure's Linux App Service.

· Web Dev Zone ·
Free Resource

waiter-with-drink-tray

Create a new App Service Plan. If you have already created then skip this step. An app service is like one container or a VM machine. In a single Azure app service, you can host N number of web apps. Based on load, you can split your apps to separate app services if required.

To create a new app service, you'll first need to set a resource group name; if you already have created it, you can use the same or else can create new. Next, fill the app service name, select Linux as your OS, select a pricing plan based on your needs, and hit create.

Note: Selecting Linux is not necessary. You can use Windows also. But, if Linux supports it why not use it. Linux App services are cheaper than Windows-based app services.

Creating a new app service plan
Creating a new app service plan


Once the app service plan is created, you'll need to create an App Service. You can search and select app service. App service is nothing but your web app/API. Create a new app under your app service plan. Select run time .Net Core 2.2. At present, .NET Core 3.3 is not listed Azure team is rolling out. But there is a workaround by which you can change to 3.0 that is explained below.

You may also like: Everything You Need to Know to Get Started With Azure Console.

Note: Select the same app service name created in the previous step; otherwise, you will end up creating a new app service plan and will be charged. It will appear in the list once you select a region.

Selecting runtime stack for web app
Selecting runtime stack for web app

After filling in these details, a next screen will be shown. Review and create your app service.

Creating app service
Creating app service

In a few minutes, the app will be deployed. Click on Go to resource, and you will be redirected to your newly created app.

Redirecting to newly cerated app
Redirecting to newly cerated app

In your app service, select Configuration tab -> General settings.

Change Version to .Net Core 3.0, which was not available in the previous step and save it.

Checking configuration settings
Checking configuration settings

Next, enable security by going to TLS/SSL Settings — Binding

Set HTTPS only — ON and save it.

Enabling security
Enabling security

Next, go to Configuration -> Application Settings.

Add some setting as shown below

WEBSITE_DYNAMIC_CACHE — 0
WEBSITE_LOCAL_CACHE_OPTION- Never (For staging enable this else app will be cached and will not refresh on publishing)
WEBSITE_WEBDEPLOY_USE_SCM — false (Set false else you will not able to use VS to publish directly)

Testing configuration settings
Testing configuration settings

Next, download the publish profile. Now, that the configuration for Azure is done, we can publish directly from Visual Studio. This process is explained below.

Getting publish profile
Getting publish profile

Open your web app in Visual Studio — 2019. Select Build → Publish.

Building via ReverseProxy
Building via ReverseProxy

Next, the Publish screen will open. Click on import and browse the publish file that we downloaded in the second to last step.

Picking a publish target and importing profile
Picking a publish target and importing profile

On importing the file, two settings will be generated: one for web deploy and other for FTP. You can select Web deploy. Finally, click Publish, and the site will be published to Azure.

Publishing
Publishing

Before publishing, click on edit and check the option, Remove additional files at the destination. Otherwise, the default Azure site will show up in Azure.

Removing additional files at destination
Removing additional files at destination

Go to Azure and restart the app service. Sometimes, it won't auto-refresh on publishing, so we need to manually restart.

Restarting our application manually
Restarting our application manually

Next, click on the Site URL. Now, the site is hosted.

Site is hosted
Site is hosted

Note: You can also configure FTP for publishing, Custom domain can also be mapped in case you don't need default Azure site URL. Firewall can be configured, and logging can be enabled. Azure also provides application insights, performance testing, etc.

Azure also supports Staging and Production slots in the higher plan using that you can first publish in staging slot and can swap to production slot after testing within seconds with almost no downtime.

There is a traffic manager inbuilt using which Azure can load balance your site.

Detailed reference can refer here:
Pricinghttps://azure.microsoft.com/en-in/pricing/details/app-service/windows/.
Documentation https://docs.microsoft.com/en-us/azure/app-service/.


Further Reading

Topics:
asp.net core ,azure ,webapp ,webapi ,linux ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}