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.
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:
Open Visual Studio and select Create a new project.
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.
In Configure your new project, name your web application project myFirstAzureWebApp, and select Create.
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.
From the Visual Studio menu, select Debug > Start Without Debugging to run your web app 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:
In Solution Explorer, right-click the myFirstAzureWebApp project and select Publish.
In Publish, select Azure and click Next.
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.
To the right of App Service instances, click +.
For Subscription, accept the subscription that is listed or select a new one from the drop-down list.
For Resource group, select New. In New resource group name, enter myResourceGroup and select OK.
For Hosting Plan, select New.
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.
In Name, enter a unique app name that includes only the valid characters are
-. You can accept the automatically generated unique name. The URL of the web app is
<app-name>is your app name.
Select Create to create the Azure resources.
Once the wizard completes, the Azure resources are created for you and you are ready to publish.
Select Finish to close the wizard.
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.
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:
In Solution Explorer, under your project, open Pages > Index.cshtml.
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>
To redeploy to Azure, right-click the myFirstAzureWebApp project in Solution Explorer and select Publish.
In the Publish summary page, select Publish.
When publishing completes, Visual Studio launches a browser to the URL of the web app.
Manage the Azure app
To manage your web app, go to the Azure portal, and search for and select App Services.
On the App Services page, select the name of your web app.
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.
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.
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.
You can follow the steps in this article using a Mac, Windows, or Linux machine.
Set up your initial environment
To complete this quickstart:
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.
Open a web browser, and navigate to the app at
You see the Hello World message from the sample app displayed in the page.
Sign into Azure
In your terminal window, log into Azure with the following command:
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
azcommand isn't recognized, be sure you have the Azure CLI installed as described in Set up your initial environment.
<app-name>with a name that's unique across all of Azure (valid characters are
-). A good pattern is to use a combination of your company name and an app identifier.
--sku F1argument 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-name>is an available Azure region. You can retrieve a list of allowable regions for your Azure account by running the
az account list-locationscommand.
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.
az webapp up command does the following actions:
Browse to the app
Browse to the deployed application using your web browser.
The .NET Core sample code is running in App Service on Linux with a built-in image.
Congratulations! You've deployed your first .NET Core app to App Service on Linux.
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
await context.Response.WriteAsync("Hello Azure!");
Save your changes, then redeploy the app using the
az webapp up command again:
az webapp up --os-type linux
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.
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.
You see your app's Overview page. Here, you can perform basic management tasks like browse, stop, start, restart, and delete.
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.