Quickstart: Deploy an ASP.NET web app

In this quickstart, you'll learn how to create and deploy your first ASP.NET web app to Azure App Service. App Service supports various versions of .NET apps, and provides a highly scalable, self-patching web hosting service. ASP.NET web apps are cross-platform and can be hosted on Linux or Windows. 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

If you've already installed Visual Studio 2022:

  1. Install the latest updates in Visual Studio by selecting Help > Check for Updates.
  2. Add the workload by selecting Tools > Get Tools and Features.
Install the latest .NET 6.0 SDK.
Install the latest .NET 6.0 SDK.
Install the latest .NET 6.0 SDK.

Create an ASP.NET web app

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

  2. In Create a new project, find, and select ASP.NET Core Web App, then select Next.

  3. In Configure your new project, name the application MyFirstAzureWebApp, and then select Next.

    Screenshot of Visual Studio - Configure ASP.NET 6.0 web app.

  4. Select .NET 6.0 (Long-term support).

  5. Ensure Authentication Type is set to None. Select Create.

    Screenshot of Visual Studio - Additional info when selecting .NET 6.0.

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

    Screenshot of Visual Studio - ASP.NET Core 6.0 running locally.

  1. In the terminal window, create a new folder named MyFirstAzureWebApp, and open it in Visual Studio Code.

    mkdir MyFirstAzureWebApp
    code MyFirstAzureWebApp
    
  2. In Visual Studio Code, open the Terminal window by typing Ctrl + `.

  3. In Visual Studio Code terminal, create a new .NET web app using the dotnet new webapp command.

    dotnet new webapp -f net6.0
    
  4. From the Terminal in Visual Studio Code, run the application locally using the dotnet run command.

    dotnet run --urls=https://localhost:5001/
    
  5. Open a web browser, and navigate to the app at https://localhost:5001.

    You'll see the template ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio Code - run .NET 6.0 in browser locally.

  1. Open a terminal window on your machine to a working directory. Create a new .NET web app using the dotnet new webapp command, and then change directories into the newly created app.

    dotnet new webapp -n MyFirstAzureWebApp --framework net6.0
    cd MyFirstAzureWebApp
    
  2. From the same terminal session, run the application locally using the dotnet run command.

    dotnet run --urls=https://localhost:5001/
    
  3. Open a web browser, and navigate to the app at https://localhost:5001.

    You'll see the template ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio Code - ASP.NET Core 6.0 in local browser.

In this step we will fork a demo project to deploy.

  • Go to the .NET 6.0 sample app.
  • Select the Fork button in the upper right on the GitHub page.
  • Select the Owner and leave the default Repository name.
  • Select Create fork.

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 resources and publish your project:

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

  2. In Publish, select Azure and then Next.

    Screenshot of Visual Studio - Publish the web app and target Azure.

  3. Choose the Specific target, either Azure App Service (Linux) or Azure App Service (Windows). Then, select Next.

    Important

    When targeting ASP.NET Framework 4.8, use Azure App Service (Windows).

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

    Screenshot of Visual Studio - Select sign in to Azure dialog.

  5. To the right of App Service instances, select +.

    Screenshot of Visual Studio - New App Service app dialog.

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

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

  8. For Hosting Plan, select New.

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

    Screenshot of Create new Hosting Plan screen in the Azure portal.

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

  11. Select Create to create the Azure resources.

    Screenshot of Visual Studio - Create app resources dialog.

    Once the wizard completes, the Azure resources are created for you and you're ready to publish your ASP.NET Core project.

  12. In the Publish dialog, ensure your new App Service app is selected in App Service instance, then select Finish. Visual Studio creates a publish profile for you for the selected App Service app.

  13. In the Publish page, select Publish. If you see a warning message, select Continue.

    Visual Studio builds, packages, and publishes the app to Azure, and then launches the app in the default browser.

    You'll see the ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio - ASP.NET Core 6.0 web app in Azure.

  1. In Visual Studio Code, open the Command Palette, Ctrl+Shift+P.

  2. Search for and select "Azure App Service: Deploy to Web App".

  3. Respond to the prompts as follows:

    1. Select MyFirstAzureWebApp as the folder to deploy.
    2. Select Add Config when prompted.
    3. If prompted, sign in to your Azure account.
    4. Select your Subscription.
    5. Select Create new Web App... Advanced.
    6. For Enter a globally unique name, use 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.
    7. Select Create new resource group and provide a name like myResourceGroup.
    8. When prompted to Select a runtime stack:
    • For .NET 6.0, select .NET 6
    • For .NET Framework 4.8, select ASP.NET V4.8
    1. Select an operating system (Windows or Linux).
      • For .NET Framework 4.8, Windows will be selected implicitly.
    2. Select a location near you.
    3. Select Create a new App Service plan, provide a name, and select the F1 Free pricing tier.
    4. Select Skip for now for the Application Insights resource.
  4. In the popup Always deploy the workspace "MyFirstAzureWebApp" to <app-name>", select Yes so that Visual Studio Code deploys to the same App Service app every time you're in that workspace.

  5. When publishing completes, select Browse Website in the notification and select Open when prompted.

    You'll see the ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio Code - ASP.NET Core 6.0 web app in Azure.

  1. Sign into your Azure account by using the az login command and following the prompt:

    az login
    
  2. Deploy the code in your local MyFirstAzureWebApp directory using the az webapp up command:

    az webapp up --sku F1 --name <app-name> --os-type <os>
    
    • If the az command isn't recognized, ensure you have the Azure CLI installed as described in Prerequisites.
    • 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.
    • Replace <os> with either linux or windows. You must use windows when targeting ASP.NET Framework 4.8.
    • 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 might 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. Then it shows a message with the app's URL:

    You can launch the app at http://<app-name>.azurewebsites.net
    
  3. Open a web browser and navigate to the URL:

    You'll see the ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of the CLI - ASP.NET Core 6.0 web app in Azure.

Note

Azure PowerShell is recommended for creating apps on the Windows hosting platform. To create apps on Linux, use a different tool, such as Azure CLI.

  1. Sign into your Azure account by using the Connect-AzAccount command and following the prompt:

    Connect-AzAccount
    
  1. Create a new app by using the New-AzWebApp command:

    New-AzWebApp -Name <app-name> -Location westeurope
    
    • Replace <app-name> with a name that's unique across all of Azure (valid characters are a-z, 0-9, and -). A combination of your company name and an app identifier is a good pattern.
    • You can optionally include the parameter -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 Get-AzLocation command.

    The command might take a few minutes to complete. While running, it creates a resource group, an App Service plan, and the App Service resource.

  2. From the application root folder, prepare your local MyFirstAzureWebApp application for deployment using the dotnet publish command:

    dotnet publish --configuration Release
    
  3. Change to the release directory and create a zip file from the contents:

    cd bin\Release\net6.0\publish
    Compress-Archive -Path * -DestinationPath deploy.zip
    
  4. Publish the zip file to the Azure app using the Publish-AzWebApp command:

    Publish-AzWebApp -ResourceGroupName myResourceGroup -Name <app-name> -ArchivePath (Get-Item .\deploy.zip).FullName -Force
    

    Note

    -ArchivePath needs the full path of the zip file.

  5. Open a web browser and navigate to the URL:

    You'll see the ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of the CLI - ASP.NET Core 6.0 web app in Azure.

  1. Type app services in the search. Under Services, select App Services.

    Screenshot of portal search in the Azure portal.

  2. In the App Services page, select + Create.

  3. In the Basics tab, under Project details, ensure the correct subscription is selected and then select to Create new resource group. Type myResourceGroup for the name.

    Screenshot of the Project details section showing where you select the Azure subscription and the resource group for the web app.

  4. Under Instance details:

    • Under Name, type a globally unique name for your web app.
    • Under Publish, select Code.
    • Under Runtime stack select .NET 6 (LTS).
    • Select an Operating System, and a Region you want to serve your app from.

    Screenshot of the App Service Instance Details with a .NET 6 runtime.

  5. Under App Service Plan, select Create new App Service Plan. Type myAppServicePlan for the name. To change to the Free tier, select Change size, select Dev/Test tab, select F1, and select the Apply button at the bottom of the page.

    Screenshot of the Administrator account section where you provide the administrator username and password.

  6. Select the Next: Deployment > button at the bottom of the page.

  7. In the Deployment tab, under GitHub Actions settings make sure Continuous deployment is Enable.

  8. Under GitHub Actions details, authenticate with your GitHub account, and select the following options:

    • For Organization select the organization where you have forked the demo project.
    • For Repository select the dotnetcore-docs-hello-world project.
    • For Branch select master.

    Screenshot of the deployment options for an app using the .NET 6 runtime.

  9. Select the Review + create button at the bottom of the page.

    Screenshot of the Review and create button at the bottom of the page.

  10. After validation runs, select the Create button at the bottom of the page.

  11. After deployment is complete, select Go to resource.

    Screenshot of the next step of going to the resource.

  12. Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net.

Update the app and redeploy

Follow these steps to update and redeploy your web app:

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

  2. Replace the first <div> element with the following code:

    <div class="jumbotron">
        <h1>.NET 💜 Azure</h1>
        <p class="lead">Example .NET app to Azure App Service.</p>
    </div>
    

    Save your changes.

  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.

    You'll see the updated ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio - Updated ASP.NET Core 6.0 web app in Azure.

  1. Open Index.cshtml.

  2. Replace the first <div> element with the following code:

    <div class="jumbotron">
        <h1>.NET 💜 Azure</h1>
        <p class="lead">Example .NET app to Azure App Service.</p>
    </div>
    

    Save your changes.

  3. In Visual Studio Code, open the Command Palette, Ctrl+Shift+P.

  4. Search for and select "Azure App Service: Deploy to Web App".

  5. Select Deploy when prompted.

  6. When publishing completes, select Browse Website in the notification and select Open when prompted.

    You'll see the updated ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of Visual Studio Code - Updated ASP.NET Core 6.0 web app in Azure.

In the local directory, open the Index.cshtml file. Replace the first <div> element:

<div class="jumbotron">
    <h1>.NET 💜 Azure</h1>
    <p class="lead">Example .NET app to Azure App Service.</p>
</div>

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

ASP.NET Core 6.0 is cross-platform, based on your previous deployment replace <os> with either linux or windows.

az webapp up --os-type <os>

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.

You'll see the updated ASP.NET Core 6.0 web app displayed in the page.

Screenshot of the CLI - Updated ASP.NET Core 6.0 web app in Azure.

  1. In the local directory, open the Index.cshtml file. Replace the first <div> element:

    <div class="jumbotron">
        <h1>.NET 💜 Azure</h1>
        <p class="lead">Example .NET app to Azure App Service.</p>
    </div>
    
  2. From the application root folder, prepare your local MyFirstAzureWebApp application for deployment using the dotnet publish command:

    dotnet publish --configuration Release
    
  3. Change to the release directory and create a zip file from the contents:

    cd bin\Release\net6.0\publish
    Compress-Archive -Path * -DestinationPath deploy.zip
    
  4. Publish the zip file to the Azure app using the Publish-AzWebApp command:

    Publish-AzWebApp -ResourceGroupName myResourceGroup -Name <app-name> -ArchivePath (Get-Item .\deploy.zip).FullName -Force
    

    Note

    -ArchivePath needs the full path of the zip file.

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

    You'll see the updated ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of the CLI - Updated ASP.NET Core 6.0 web app in Azure.

  1. Browse to your GitHub fork of the sample code.

  2. On your repo page, press . to start Visual Studio code within your browser.

    Note

    The URL will change from GitHub.com to GitHub.dev. This feature only works with repos that have files. This does not work on empty repos.

  3. Open Index.cshtml.

    Index.cshtml is located in the Pages folder.

    Screenshot of the Explorer window from Visual Studio Code in the browser, highlighting the Index.cshtml in the dotnetcore-docs-hello-world repo.

  4. Replace the first <div> element with the following code:

    <div class="jumbotron">
        <h1>.NET 💜 Azure</h1>
        <p class="lead">Example .NET app to Azure App Service.</p>
    </div>
    

    Save your changes.

  5. From the Source Control menu, select the Stage Changes button to stage the change.

  6. Enter a commit message such as We love Azure. Then, select Commit and Push.

  7. Once deployment has completed, return to the browser window that opened during the Browse to the app step, and refresh the page.

    You'll see the updated ASP.NET Core 6.0 web app displayed in the page.

    Screenshot of the CLI - Updated ASP.NET Core 6.0 web app in Azure.

Manage the Azure app

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

Screenshot of the Azure portal - Select App Services option.

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

Screenshot of the Azure portal - 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.

Screenshot of the Azure portal - App Service overview page.

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.

  1. From your web app's Overview page in the Azure portal, select the myResourceGroup link under Resource group.
  2. On the resource group page, make sure that the listed resources are the ones you want to delete.
  3. Select Delete, type myResourceGroup in the text box, and then select Delete.

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.

  1. From your web app's Overview page in the Azure portal, select the myResourceGroup link under Resource group.
  2. On the resource group page, make sure that the listed resources are the ones you want to delete.
  3. Select Delete, type myResourceGroup in the text box, and then select Delete.

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.

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 PowerShell command:

Remove-AzResourceGroup -Name myResourceGroup

This command may take a minute to run.

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.

  1. From your web app's Overview page in the Azure portal, select the myResourceGroup link under Resource group.
  2. On the resource group page, make sure that the listed resources are the ones you want to delete.
  3. Select Delete, type myResourceGroup in the text box, and then select Delete.

Next steps

In this quickstart, you created and deployed an ASP.NET 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: