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

Prerequisites

If youve 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.

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.

    Visual Studio - Configure ASP.NET 6.0 web app.

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

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

    Visual Studio - Additional info when selecting .NET Core 6.0.

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

    Visual Studio - ASP.NET Core 6.0 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, youll 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.

    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 youre 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 youre already signed in, select the account you want.

    Visual Studio - Select sign in to Azure dialog.

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

    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:

    SettingSuggested valueDescription
    Hosting PlanMyFirstAzureWebAppPlanName of the App Service plan.
    LocationWest EuropeThe datacenter where the web app is hosted.
    SizeFreePricing tier determines hosting features.

    Create new Hosting Plan

  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://.azurewebsites.net, where  is your app name.

  11. Select Create to create the Azure resources.

    Visual Studio - Create app resources dialog.

    Once the wizard completes, the Azure resources are created for you and youre 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.

    Youll see the ASP.NET Core 6.0 web app displayed in the page.

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

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 

     element with the following code:

    razor
    
        

    .NET 💜 Azure

    Example .NET app to Azure App Service.

    " style="box-sizing: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; outline-color: inherit; line-height: 1.3571; border: 0px; display: block; padding: 0px; position: relative;"><div class="jumbotron"> <h2>.NET 💜 Azureh2> <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.

    Youll see the updated ASP.NET Core 6.0 web app displayed in the page.

    Visual Studio - 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.

Azure portal - Select App Services option.

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

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.

Azure portal - App Service overview page.

Clean up resources

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

  1. From your web apps 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 Video to learn how to create a .NET Core app and connect it to a SQL Database: