Quickstart: Create an ASP.NET Core web app in Azure

In this quickstart, you'll learn how to create and deploy your first ASP.NET Core web app to Azure App Service. App Service supports .NET 5.0 apps.

When you're finished, you'll have an Azure resource group consisting of an App Service hosting plan and an App Service with a deployed web application.

Prerequisites

  • An Azure account with an active subscription. Create an account for free.

  • Install Visual Studio 2019 with the ASP.NET and web development workload.

    If you've installed Visual Studio 2019 already:

    • Install the latest updates in Visual Studio by selecting Help > Check for Updates. The latest updates contain the .NET 5.0 SDK.
    • Add the workload by selecting Tools > Get Tools and Features.

Create an ASP.NET Core web app

Create an ASP.NET Core web app in Visual Studio by following these steps:

  1. Open Visual Studio and select Create a new project.

  2. In Create a new project, select ASP.NET Core Web Application and confirm that C# is listed in the languages for that choice, then select Next.

  3. In Configure your new project, name your web application project myFirstAzureWebApp, and select Create.

    Configure your web app project

  4. You can deploy any type of ASP.NET Core web app to Azure, but for this quickstart, choose the Web Application template. Make sure Authentication is set to No Authentication, and that no other option is selected. Then, select Create.

    Create a new ASP.NET Core web app

  5. From the Visual Studio menu, select Debug > Start Without Debugging to run your web app locally.

    Web app running locally

Publish your web app

To publish your web app, you must first create and configure a new App Service that you can publish your app to.

As part of setting up the App Service, you'll create:

  • A new resource group to contain all of the Azure resources for the service.
  • A new Hosting Plan that specifies the location, size, and features of the web server farm that hosts your app.

Follow these steps to create your App Service and publish your web app:

  1. In Solution Explorer, right-click the myFirstAzureWebApp project and select Publish.

  2. In Publish, select Azure and click Next.

  3. Your options depend on whether you're signed in to Azure already and whether you have a Visual Studio account linked to an Azure account. Select either Add an account or Sign in to sign in to your Azure subscription. If you're already signed in, select the account you want.

    Sign in to Azure

  4. To the right of App Service instances, click +.

    New App Service app

  5. For Subscription, accept the subscription that is listed or select a new one from the drop-down list.

  6. For Resource group, select New. In New resource group name, enter myResourceGroup and select OK.

  7. For Hosting Plan, select New.

  8. In the Hosting Plan: Create new dialog, enter the values specified in the following table:

    Setting Suggested Value Description
    Hosting Plan myFirstAzureWebAppPlan Name of the App Service plan.
    Location West Europe The datacenter where the web app is hosted.
    Size Free Pricing tier determines hosting features.

    Create new Hosting Plan

  9. In Name, enter a unique app name that includes only the valid characters are a-z, A-Z, 0-9, and -. You can accept the automatically generated unique name. The URL of the web app is http://<app-name>.azurewebsites.net, where <app-name> is your app name.

  10. Select Create to create the Azure resources.

    Create app resources

    Once the wizard completes, the Azure resources are created for you and you are ready to publish.

  11. Select Finish to close the wizard.

  12. In the Publish page, click Publish. Visual Studio builds, packages, and publishes the app to Azure, and then launches the app in the default browser.

    Published ASP.NET web app running in Azure

Congratulations! Your ASP.NET Core web app is running live in Azure App Service.

Update the app and redeploy

Follow these steps to update and redeploy your web app:

  1. In Solution Explorer, under your project, open Pages > Index.cshtml.

  2. Replace the entire <div> tag with the following code:

    <div class="jumbotron">
        <h1>ASP.NET in Azure!</h1>
        <p class="lead">This is a simple app that we've built that demonstrates how to deploy a .NET app to Azure App Service.</p>
    </div>
    
  3. To redeploy to Azure, right-click the myFirstAzureWebApp project in Solution Explorer and select Publish.

  4. In the Publish summary page, select Publish.

    When publishing completes, Visual Studio launches a browser to the URL of the web app.

    Updated ASP.NET web app running in Azure

Manage the Azure app

To manage your web app, go to the Azure portal, and search for and select App Services.

Select App Services

On the App Services page, select the name of your web app.

Screenshot of the App Services page with an example web app selected.

The Overview page for your web app, contains options for basic management like browse, stop, start, restart, and delete. The left menu provides further pages for configuring your app.

App Service in Azure portal

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group.

From the Azure portal menu or Home page, select Resource groups. Then, on the Resource groups page, select myResourceGroup.

On the myResourceGroup page, make sure that the listed resources are the ones you want to delete.

Select Delete resource group, type myResourceGroup in the text box to confirm, and then select Delete.

Next steps

In this quickstart, you used Visual Studio to create and deploy an ASP.NET Core web app to Azure App Service.

Advance to the next article to learn how to create a .NET Core app and connect it to a SQL Database:

App Service on Linux provides a highly scalable, self-patching web hosting service using the Linux operating system. This quickstart shows how to create a .NET Core app on App Service on Linux. You create the app using the Azure CLI, and you use Git to deploy the .NET Core code to the app.

Sample app running in Azure

You can follow the steps in this article using a Mac, Windows, or Linux machine.

If you don't have an Azure subscription, create a free account before you begin.

Set up your initial environment

Having issues? Let us know.

Create the app locally

In a terminal window on your machine, create a directory named hellodotnetcore and change the current directory to it.

mkdir hellodotnetcore
cd hellodotnetcore

Create a new .NET Core app.

dotnet new web

Run the app locally

Run the application locally so that you see how it should look when you deploy it to Azure.

dotnet run

Open a web browser, and navigate to the app at http://localhost:5000.

You see the Hello World message from the sample app displayed in the page.

Test with browser

Having issues? Let us know.

Sign into Azure

In your terminal window, log into Azure with the following command:

az login

Deploy the app

Deploy the code in your local folder (hellodotnetcore) using the az webapp up command:

az webapp up --sku F1 --name <app-name> --os-type linux
  • If the az command isn't recognized, be sure you have the Azure CLI installed as described in Set up your initial environment.
  • Replace <app-name> with a name that's unique across all of Azure (valid characters are a-z, 0-9, and -). A good pattern is to use a combination of your company name and an app identifier.
  • The --sku F1 argument creates the web app on the Free pricing tier. Omit this argument to use a faster premium tier, which incurs an hourly cost.
  • You can optionally include the argument --location <location-name> where <location-name> is an available Azure region. You can retrieve a list of allowable regions for your Azure account by running the az account list-locations command.

The command may take a few minutes to complete. While running, it provides messages about creating the resource group, the App Service plan and hosting app, configuring logging, then performing ZIP deployment. It then gives the message, "You can launch the app at http://<app-name>.azurewebsites.net", which is the app's URL on Azure.

Having issues? Let us know.

Note

The az webapp up command does the following actions:

Browse to the app

Browse to the deployed application using your web browser.

http://<app_name>.azurewebsites.net

The .NET Core sample code is running in App Service on Linux with a built-in image.

Sample app running in Azure

Congratulations! You've deployed your first .NET Core app to App Service on Linux.

Having issues? Let us know.

Update and redeploy the code

In the local directory, open the Startup.cs file. Make a small change to the text in the method call context.Response.WriteAsync:

await context.Response.WriteAsync("Hello Azure!");

Save your changes, then redeploy the app using the az webapp up command again:

az webapp up

This command uses values that are cached locally in the .azure/config file, including the app name, resource group, and App Service plan.

Once deployment has completed, switch back to the browser window that opened in the Browse to the app step, and hit refresh.

Updated sample app running in Azure

Having issues? Let us know.

Manage your new Azure app

Go to the Azure portal to manage the app you created.

From the left menu, click App Services, and then click the name of your Azure app.

Screenshot of the App Services page showing an example Azure app selected.

You see your app's Overview page. Here, you can perform basic management tasks like browse, stop, start, restart, and delete.

App Service page in Azure portal

The left menu provides different pages for configuring your app.

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, delete the resource group by running the following command in the Cloud Shell:

az group delete --name myResourceGroup

This command may take a minute to run.

Having issues? Let us know.

Next steps