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 (An HTTP-based service for hosting web applications, REST APIs, and mobile back-end applications.). App Service supports .NET 5.0 apps.

When you're finished, you'll have an Azure resource group (A logical container for related Azure resources that you can manage as a unit.) consisting of an App Service plan (The plan that specifies the location, size, and features of the web server farm that hosts your app.) and on App Service app (The representation of your web app, which contains your app code, DNS hostnames, certificates, and related resources.) with a deployed sample ASP.NET Core application.

1. Prepare your environment

  • Get an Azure account with an active subscription (The basic organizational structure in which you manage resources in Azure, typically associated with an individual or department within an organization.). Create an account for free.
  • Install Visual Studio 2019 with the ASP.NET and web development workload.
Already have Visual Studio 2019? 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.

2. Create an ASP.NET Core web app

  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. For a .NET 5.0 app, select ASP.NET Core 5.0 in the dropdown. Otherwise, use the default value.

  5. You can deploy any type of ASP.NET Core web app to Azure, but for this quickstart, choose the ASP.NET Core Web App 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

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

    Web app running locally

3. Publish your web app

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

  2. In Publish, select Azure and select 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, select +.

    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
    Hosting Plan myFirstAzureWebAppPlan
    Location West Europe
    Size Free

    Create new Hosting Plan

  9. In Name, enter a unique app name.

    Which characters can I use? 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

  11. Wait for the wizard to finish creating Azure resources. Select Finish to close the wizard.

  12. In the Publish page, select Publish to deploy your project.

    What's Visual Studio doing? 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

4. Update the app and redeploy

  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>
  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

5. Manage the Azure app

  1. Go to the Azure portal, and search for and select App Services.

    Select App Services

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

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

  3. 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

6. Clean up resources

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

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

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

Next steps

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

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

1. Prepare your environment

Having issues? Let us know.

2. Create the app locally

  1. Run mkdir hellodotnetcore to create the directory.

    mkdir hellodotnetcore
  2. Run cd hellodotnetcore to change the directory.

    cd hellodotnetcore
  3. Run dotnet new web to create a new .NET Core app.

    dotnet new web

3. Run the app locally

  1. Run dotnet run to see how it looks when you deploy it to Azure.

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

Test with browser

Having issues? Let us know.

4. Sign into Azure

Run az login to sign into Azure.

az login

Having issues? Let us know.

5. Deploy the app

  1. Run az webapp up in your local folder. Replace <app-name> with a globally unique name.

    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 Prepare your 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.
  2. Wait for the command to complete. It may take a few minutes, and ends with "You can launch the app at http://<app-name>.azurewebsites.net".

    What's az webapp up doing?

    The az webapp up command does the following actions:

    • Create a default resource group.
    • Create a default App Service plan.
    • Create an App Service app with the specified name.
    • Zip deploy files from the current working directory to the app.
    • While running, it provides messages about resource creation, logging, and ZIP deployment.

Having issues? Let us know.

6. Browse to the app

Browse to the deployed application using your web browser.


Sample app running in Azure

Having issues? Let us know.

7. Update and redeploy the code

  1. Open the Startup.cs file in the local directory.

  2. Make a small change to the text in the method call context.Response.WriteAsync.

    await context.Response.WriteAsync("Hello Azure!");
  3. Save your changes.

  4. Run az webapp up to redeploy:

    az webapp up --os-type linux
    What's az webapp up doing this time? The first time you ran the command, it saved the app name, resource group, and App Service plan in the .azure/config file from the project root. When you run it again from the project root, it uses the values saved in .azure/config, detects that the App Service resources already exist, and performs Zip deploy again.
  5. Once deployment has completed, hit refresh in the browser window that previously opened.

    Updated sample app running in Azure

Having issues? Let us know.

8. Manage your new Azure app

  1. Go to the Azure portal.

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

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

  3. The Overview page is where you can perform basic management tasks like browse, stop, start, restart, and delete. The left menu provides different pages for configuring your app.

    App Service page in Azure portal

9. Clean up resources

Run az group delete --name myResourceGroup to delete the resource group.

az group delete --name myResourceGroup

Having issues? Let us know.

Next steps