Quickstart: Deploy an ASP.NET web app - Azure App Service (2024)

Edit

Share via

  • Article

Note

Starting June 1, 2024, all newly created App Service apps will have the option to generate a unique default hostname using the naming convention <app-name>-<random-hash>.<region>.azurewebsites.net. Existing app names will remain unchanged.

Example: myapp-ds27dh7271aah175.westus-01.azurewebsites.net

For further details, refer to Unique Default Hostname for App Service Resource.

In this quickstart, you 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 have an Azure resource group consisting of an App Service hosting plan and an App Service with a deployed web application.

Alternatively, you can deploy an ASP.NET web app as part of a Windows or Linux container in App Service.

Tip

Find GitHub Copilot tips in the Visual Studio, Visual Studio Code, and Azure portal steps.

Prerequisites

  • .NET 8.0
  • .NET Framework 4.8
  • An Azure account with an active subscription. Create an account for free.
  • Visual Studio 2022 with the ASP.NET and web development workload.
  • (Optional) To try GitHub Copilot, a GitHub Copilot account. A 30-day free trial is available.

If you 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.
  • An Azure account with an active subscription. Create an account for free.
  • The Azure CLI.
  • The latest .NET 8.0 SDK.
  • (Optional) To try GitHub Copilot, a GitHub Copilot account. A 30-day free trial is available.
  • An Azure account with an active subscription. Create an account for free.
  • The Azure PowerShell.
  • The latest .NET 8.0 SDK.
  • An Azure account with an active subscription. Create an account for free.
  • The Azure Developer CLI
  • The latest .NET 8.0 SDK.

1. Create an ASP.NET web app

1. Initialize the ASP.NET web app template

  • .NET 8.0
  • .NET Framework 4.8
  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 (Razor Pages), then select Next.

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

  4. Select .NET 8.0 (Long Term Support).

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

  6. From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally. If you see a message asking you to trust a self-signed certificate, select Yes.

Tip

If you have a GitHub Copilot account, try getting GitHub Copilot features for Visual Studio.

  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 net8.0cd 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 see the template ASP.NET Core 8.0 web app displayed in the page.

In this step, you fork a demo project to deploy.

  • .NET 8.0
  • .NET Framework 4.8
  1. Go to the .NET 8.0 sample app.
  2. Select the Fork button in the upper right on the GitHub page.
  3. Select the Owner and leave the default Repository name.
  4. Select Create fork.

This quickstart uses the Azure Developer CLI (azd) both to create Azure resources and deploy code to it. For more information about Azure Developer CLI, visit the documentation or training path.

Retrieve and initialize the ASP.NET Core web app template for this quickstart using the following steps:

  1. Open a terminal window on your machine to an empty working directory. Initialize the azd template using the azd init command.

    azd init --template https://github.com/Azure-Samples/quickstart-deploy-aspnet-core-app-service.git

    When prompted for an environment name, enter dev.

  2. From the same terminal session, run the application locally using the dotnet run command. Use the --project parameter to specify the src directory of the azd template, which is where the application code lives.

    dotnet run --project src --urls=https://localhost:5001/
  3. Open a web browser and navigate to the app at https://localhost:5001. The ASP.NET Core 8.0 web app template is displayed on the page.

2. Publish your web 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.

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

  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.

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

  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:

    SettingSuggested valueDescription
    Hosting PlanMyFirstAzureWebAppPlanName of the App Service plan.
    LocationWest EuropeThe datacenter where the web app is hosted.
    SizeChoose the lowest tier.Pricing tiers define hosting features.
  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.

    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, then select Finish, then select Close. 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.

    • .NET 8.0
    • .NET Framework 4.8

    You see the ASP.NET Core 8.0 web app displayed in the page.

  1. Open Visual Studio Code from your project's root directory.

    code .
  2. If prompted, select Yes, I trust the authors.

    Tip

    If you have a GitHub Copilot account, try getting GitHub Copilot features for Visual Studio Code.

  3. In Visual Studio Code, open the Command Palette by selecting View > Command Palette.

  4. Search for and select "Azure App Service: Create New Web App (Advanced)".

  5. Respond to the prompts as follows:

    1. If prompted, sign in to your Azure account.
    2. Select your Subscription.
    3. Select Create new Web App... Advanced.
    4. 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.
    5. Select Create new resource group and provide a name like myResourceGroup.
    6. When prompted to Select a runtime stack, select .NET 8 (LTS).
    7. Select an operating system (Windows or Linux).
    8. Select a location near you.
    9. Select Create new App Service plan, provide a name, and select the Free (F1) pricing tier.
    10. Select Skip for now for the Application Insights resource.
    11. When prompted, select Deploy.
    12. Select MyFirstAzureWebApp as the folder to deploy.
    13. Select Add Config when prompted.
  6. 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.

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

    You see the ASP.NET Core 8.0 web app displayed in the page.

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

    az login
    • If the az command isn't recognized, ensure you have the Azure CLI installed as described in Prerequisites.
  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>
    • 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 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 it's running, the command 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 see the ASP.NET Core 8.0 web app displayed in the page.

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 -ResourceGroupName myResourceGroup -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 it's running, the command 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\net8.0\publishCompress-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 see the ASP.NET Core 8.0 web app displayed in the page.

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

    Quickstart: Deploy an ASP.NET web app - Azure App Service (14)

  2. In the App Services page, select Create > Web App.

  3. In the Basics tab:

    • .NET 8.0
    • .NET Framework 4.8
    • Under Resource group, select Create new. Type myResourceGroup for the name.
    • Under Name, type a globally unique name for your web app.
    • Under Publish, select Code.
    • Under Runtime stack select .NET 8 (LTS).
    • Under Operating System, select Windows. If you select Linux, you can't configure GitHub deployment in the next step, but you can still do it after creating the app in the Deployment Center page.
    • Select a Region you want to serve your app from.
    • Under App Service Plan, select Create new and type myAppServicePlan for the name.
    • Under Pricing plan, select Free F1.

  4. Select the Deployment tab at the top of the page

  5. Under GitHub Actions settings, set Continuous deployment to Enable.

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

    • .NET 8.0
    • .NET Framework 4.8
    • For Organization select the organization where you forked the demo project.
    • For Repository select the dotnetcore-docs-hello-world project.
    • For Branch select main.

    Note

    By default, the creation wizard disables basic authentication and GitHub Actions deployment is created using a user-assigned identity. If you get a permissions error during resource creation, your Azure account may not have enough permissions. You can configure GitHub Actions deployment later with an identity generated for you by an Azure administrator, or you can also enable basic authentication instead.

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

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

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

    Quickstart: Deploy an ASP.NET web app - Azure App Service (17)

  10. Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net. If you see the message "Your web app is running and waiting for your content", GitHub deployment is still running. Wait a couple of minutes and refresh the page.

    • .NET 8.0
    • .NET Framework 4.8

The AZD template contains files that generate the following required resources for your application to run in App service:

  • A new resource group to contain all of the Azure resources for the service.
  • A new App Service plan that specifies the location, size, and features of the web server farm that hosts your app.
  • A new App Service app instance to run the deployed application.
  1. Sign into your Azure account by using the azd auth login command and following the prompt:

    azd auth login
  2. Create the Azure resources and deploy your app using the azd up command:

    azd up

    The azd up command might take a few minutes to complete. azd up uses the Bicep files in your projects to create the resource group, App Service Plan, and hosting app. It also performs certain configurations such as enabling logging and deploys your compiled app code. While it's running, the command provides messages about the provisioning and deployment process, including a link to the deployment in Azure. When it finishes, the command also displays a link to the deploy application.

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

    You see the ASP.NET Core 8.0 web app displayed in the page.

3. Update the app and redeploy

You'll make a change to Index.cshtml and redeploy to see the changes. In the .NET 8.0 template, it's in the Pages folder. In the .NET Framework 4.8 template, it's in the Views/Home folder. 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>

    Tip

    With GitHub Copilot enabled in Visual Studio, try the following:

    1. Select the <div> element and type Alt+/.
    2. Ask Copilot, "Change to a Bootstrap card that says .NET 💜 Azure."

    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.

    • .NET 8.0
    • .NET Framework 4.8

    You see the updated ASP.NET Core 8.0 web app displayed in the page.

  1. Open Pages/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>

    Tip

    Try this with GitHub Copilot:

    1. Select the entire <div> element and click Quickstart: Deploy an ASP.NET web app - Azure App Service (21).
    2. Ask Copilot, "Change to a Bootstrap card that says .NET 💜 Azure."

    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 the subscription and the web app you used earlier.

  6. When prompted, select Deploy.

  7. When publishing completes, select Browse Website in the notification.

    You see the updated ASP.NET Core 8.0 web app displayed in the page.

Tip

To see how Visual Studio Code with GitHub Copilot helps improve your web development experience, see the Visual Studio Code steps.

In the local directory, open the Pages/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 and 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 completes, switch back to the browser window that opened in the Browse to the app step, and hit refresh.

You see the updated ASP.NET Core 8.0 web app displayed in the page.

  1. In the local directory, open the Pages/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\net8.0\publishCompress-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 completes, switch back to the browser window that opened in the Browse to the app step, and hit refresh.

    You see the updated ASP.NET Core 8.0 web app displayed in the page.

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

  2. On your repo page, create a codespace by selecting Code > Create codespace on main.

    • .NET 8.0
    • .NET Framework 4.8

    Quickstart: Deploy an ASP.NET web app - Azure App Service (25)

    Tip

    If you have a GitHub Copilot account, try getting GitHub Copilot features in your codespace.

  3. Open Index.cshtml.

    • .NET 8.0
    • .NET Framework 4.8

    Index.cshtml is located in the Pages folder.

    Quickstart: Deploy an ASP.NET web app - Azure App Service (26)

  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>

    The changes are automatically saved.

    Tip

    Try this with GitHub Copilot:

    1. Select the entire <div> element and click Quickstart: Deploy an ASP.NET web app - Azure App Service (27).
    2. Ask Copilot, "Change to a Bootstrap card that says .NET 💜 Azure."
  5. From the Source Control menu, enter a commit message such as Modify homepage. Then, select Commit and confirm staging the changes by selecting Yes.

    • .NET 8.0
    • .NET Framework 4.8

    Quickstart: Deploy an ASP.NET web app - Azure App Service (28)

    Tip

    Let GitHub Copilot create a commit message for you by selecting Quickstart: Deploy an ASP.NET web app - Azure App Service (29) in the message box.

  6. Select Sync changes 1, then confirm by selecting OK.

  7. It takes a few minutes for the deployment to run. To view the progress, navigate to https://github.com/<your-github-alias>/dotnetcore-docs-hello-world/actions.

  8. Return to the browser window that opened during the Browse to the app step, and refresh the page.

    • .NET 8.0
    • .NET Framework 4.8

    You see the updated ASP.NET Core 8.0 web app displayed in the page.

In the local directory, open the src/Pages/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 azd up command again:

azd up

azd up skips the provisioning resources step this time and only redeploys your code, since there are no changes to the Bicep files.

Once deployment completes, the browser opens to the updated ASP.NET Core 8.0 web app.

4. Manage the Azure app

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

Quickstart: Deploy an ASP.NET web app - Azure App Service (32)

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

Quickstart: Deploy an ASP.NET web app - Azure App Service (33)

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.

Quickstart: Deploy an ASP.NET web app - Azure App Service (34)

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 resource group, type myResourceGroup in the text box, and then select Delete.
  4. Confirm again by selecting 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 resource group, type myResourceGroup in the text box, and then select Delete.
  4. Confirm again by selecting Delete.

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

For your convenience, the az webapp up command you ran earlier in this project saves the resource group name as the default value whenever you run az commands from this project.

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 resource group, type myResourceGroup in the text box, and then select Delete.
  4. Confirm again by selecting Delete.

Clean up resources

Use the azd down command to remove the resource group and all resources associated with it:

azd down

Visit the Azure Developer CLI documentation for next steps on working with azd templates and additional features.

Next steps

  • .NET 8.0
  • .NET Framework 4.8

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

Tutorial: ASP.NET Core app with SQL database

Configure ASP.NET Core app

Learn more about the Azure Developer CLI

Feedback

Was this page helpful?

Quickstart: Deploy an ASP.NET web app - Azure App Service (2024)
Top Articles
How much do I need to retire at 60? (12 point retirement checklist)
Three Reasons Some People Choose to Never Retire
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 6142

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.