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
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.
For a .NET 5.0 app, select ASP.NET Core 5.0 in the dropdown. Otherwise, use the default value.
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.
From the Visual Studio menu, select Debug > Start Without Debugging to run your web app locally.
3. Publish your web app
In Solution Explorer, right-click the myFirstAzureWebApp project and select Publish.
In Publish, select Azure and select 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, select +.
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 Hosting Plan myFirstAzureWebAppPlan Location West Europe Size Free 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.Select Create to create the Azure resources.
Wait for the wizard to finish creating Azure resources. Select Finish to close the wizard.
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.
4. Update the app and redeploy
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.
5. Manage the Azure 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.
6. Clean up resources
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.
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
- Get an Azure account with an active subscription. Create an account for free.
- Install the latest .NET Core 3.1 SDK or .NET 5.0 SDK.
- Install the latest Azure CLI.
2. Create the app locally
Run
mkdir hellodotnetcore
to create the directory.mkdir hellodotnetcore
Run
cd hellodotnetcore
to change the directory.cd hellodotnetcore
Run
dotnet new web
to create a new .NET Core app.dotnet new web
3. Run the app locally
Run
dotnet run
to see how it looks when you deploy it to Azure.dotnet run
Open a web browser, and navigate to the app at
http://localhost:5000
.
4. Sign into Azure
Run az login
to sign into Azure.
az login
5. Deploy the app
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
Troubleshooting
- 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 area-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 theaz account list-locations
command.
- If the
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.
6. Browse to the app
Browse to the deployed application using your web browser.
http://<app_name>.azurewebsites.net
7. Update and redeploy the code
Open the Startup.cs file in the local directory.
Make a small change to the text in the method call
context.Response.WriteAsync
.await context.Response.WriteAsync("Hello Azure!");
Save your changes.
Run
az webapp up
to redeploy:az webapp up --os-type linux
What's
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.az webapp up
doing this time?Once deployment has completed, hit refresh in the browser window that previously opened.
8. Manage your new Azure app
Go to the Azure portal.
From the left menu, select App Services, and then select the name of your Azure app.
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.
9. Clean up resources
Run az group delete --name myResourceGroup
to delete the resource group.
az group delete --name myResourceGroup
Next steps
Feedback
Submit and view feedback for