Azure  

Deploying Web Apps on Azure App Service: A Step-by-Step Guide Using C#

1. Introduction to Azure App Service

In today’s fast-paced digital landscape, deploying and managing web applications efficiently is as crucial as developing them. Businesses and developers are continuously seeking reliable, scalable, and secure platforms to host their web solutions without the overhead of managing physical servers or complex infrastructure. This is where Azure App Service steps in, Microsoft’s fully managed Platform as a Service (PaaS) offering that simplifies the entire lifecycle of web application deployment.

Azure App Service allows developers to build, deploy, and scale powerful web applications and APIs using popular frameworks such as .NET, Node.js, Java, Python, PHP, and Ruby. It eliminates the need for manual infrastructure management by providing a secure, scalable environment backed by Microsoft’s global cloud infrastructure. Whether you're running a small startup website or a large-scale enterprise application, Azure App Service offers features like auto-scaling, load balancing, custom domains, SSL certificates, and integrated DevOps support, making it a complete solution for web app hosting.

In this guide, we’ll take a step-by-step journey through the process of deploying web apps to Azure App Service. You’ll learn how to create and configure an App Service Plan, build and deploy your web application using multiple approaches, including Visual Studio, Azure CLI, and the Azure SDK for .NET (C#), and set up continuous deployment pipelines for automation. By the end, you’ll be equipped with the practical knowledge to deploy production-ready applications to Azure with confidence.

2. Why Use Azure App Service

Key advantages include:

  • Fully Managed Platform: No need to manage servers or runtime.

  • Multiple Languages: Supports .NET, Node.js, Java, Python, and PHP.

  • Auto Scaling and Load Balancing: Handles traffic spikes seamlessly.

  • Integrated Monitoring: Application Insights integration for analytics.

  • DevOps Ready: Supports CI/CD from GitHub, Azure DevOps, or Bitbucket.

  • Secure: Integrated authentication with Azure AD, GitHub, Google, and more.

3. Understanding the Deployment Process

The deployment process involves several stages:

  1. Building the web application (ASP.NET Core MVC or Web API).

  2. Creating an Azure App Service Plan (defines compute resources).

  3. Creating the Web App (host environment).

  4. Deploying code or binaries to the web app.

  5. Configuring environment settings such as connection strings or app secrets.

  6. Monitoring and scaling based on demand.

4. Prerequisites

Before deploying your app, ensure the following:

  • An Azure subscription (you can start with a free account).

  • Visual Studio 2022 or Visual Studio Code installed.

  • Azure CLI (az) installed and configured (az login).

  • A published ASP.NET Core project ready for deployment.

5. Creating and Configuring an App Service Plan

An App Service Plan determines region, instance size, and scaling.

Using Azure Portal

  1. Navigate to Azure Portal → App Services → Create.

  2. Select your Subscription and Resource Group.

  3. Under Hosting, create a new App Service Plan.

  4. Choose the Pricing tier (Free, Basic, Standard, or Premium).

  5. Click Review + CreateCreate.

Using Azure CLI


# Create Resource Group
az group create --name MyResourceGroup --location eastus

# Create App Service Plan
az appservice plan create --name MyAppServicePlan --resource-group MyResourceGroup --sku B1

Using C# and Azure SDK

You can also automate this setup with C# using the Azure.ResourceManager library.


using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AppService;
using Azure.ResourceManager.Resources;

var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);

// Create or get resource group
string rgName = "MyResourceGroup";
string location = "EastUS";
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().CreateOrUpdateAsync(
    rgName,
    new ResourceGroupData(location)
);

// Create App Service Plan
var appServicePlanCollection = resourceGroup.GetAppServicePlans();
var planData = new AppServicePlanData(location)
{
    Sku = new Azure.ResourceManager.AppService.Models.SkuDescription
    {
        Name = "B1",
        Tier = "Basic",
        Capacity = 1
    }
};

var appServicePlan = await appServicePlanCollection.CreateOrUpdateAsync("MyAppServicePlan", planData);
Console.WriteLine($"App Service Plan Created: {appServicePlan.Value.Data.Name}");

6. Creating an Azure Web App

Once the plan is ready, create the Web App to host your application.

Using Azure CLI


az webapp create --resource-group MyResourceGroup \
    --plan MyAppServicePlan \
    --name mywebappdemo123 \
    --runtime "DOTNETCORE:8.0"

Using C# (Azure SDK)


var webAppCollection = resourceGroup.GetWebSites();
var webAppData = new SiteData(location)
{
    ServerFarmId = appServicePlan.Value.Id,
    SiteConfig = new SiteConfigProperties
    {
        NetFrameworkVersion = "v8.0"
    }
};

var webApp = await webAppCollection.CreateOrUpdateAsync("MyWebAppDemo", webAppData);
Console.WriteLine($"Web App Created: {webApp.Value.Data.DefaultHostName}");

7. Deploying Your Application

Option 1: Deploy via Visual Studio

  1. Open your project in Visual Studio.

  2. Right-click the project → Publish.

  3. Choose Azure → Azure App Service (Windows/Linux).

  4. Sign in to Azure, select your Subscription, Resource Group, and Web App.

  5. Click Publish.

Visual Studio will build, package, and deploy your app to Azure App Service.

Option 2: Deploy Using Azure CLI


az webapp deploy --resource-group MyResourceGroup \
  --name MyWebAppDemo \
  --src-path "C:\Projects\MyApp\publish"

Option 3: Deploy Using C#

You can deploy directly from C# using the Kudu ZIP API.


using System.Net.Http;
using System.Net.Http.Headers;

string webAppName = "MyWebAppDemo";
string publishZip = @"C:\Projects\MyApp\publish.zip";
string userName = "$MyWebAppDemo"; // From publish profile
string password = "<your-deployment-password>";
string kuduUrl = $"https://{webAppName}.scm.azurewebsites.net/api/zipdeploy";

using var client = new HttpClient();
var byteContent = new ByteArrayContent(System.IO.File.ReadAllBytes(publishZip));
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Basic",
    Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{userName}:{password}")));

var response = await client.PostAsync(kuduUrl, byteContent);
Console.WriteLine(await response.Content.ReadAsStringAsync());

8. Managing App Settings and Configuration

You can configure connection strings or secrets in Azure App Service without modifying your code.

Using Azure CLI


az webapp config appsettings set \
    --name MyWebAppDemo \
    --resource-group MyResourceGroup \
    --settings "ConnectionStrings__DefaultConnection=Server=tcp:mydb.database.windows.net;Database=MyDB;..."

Using C#


var configSettings = new[]
{
    new NameValuePair("ConnectionStrings__DefaultConnection", "Server=tcp:mydb.database.windows.net;Database=MyDB;...")
};

await webApp.Value.GetApplicationSettings().CreateOrUpdateAsync(configSettings);
Console.WriteLine("App settings configured successfully.");

9. Setting Up Continuous Deployment with GitHub Actions

  1. Navigate to your Web App → Deployment Center.

  2. Choose GitHub → Authorize Azure App Service.

  3. Select your Repository and Branch.

  4. Azure will generate a GitHub Actions YAML file similar to:


name: Build and Deploy to Azure WebApp
on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0.x'
      - name: Build
        run: dotnet publish -c Release -o publish_output
      - name: Deploy to Azure WebApp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'MyWebAppDemo'
          publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
          package: publish_output

10. Monitoring and Scaling

Enable Application Insights


az monitor app-insights component create \
    --app MyAppInsights \
    --location eastus \
    --resource-group MyResourceGroup

Attach it to your Web App:


az webapp config appsettings set \
    --resource-group MyResourceGroup \
    --name MyWebAppDemo \
    --settings "APPINSIGHTS_INSTRUMENTATIONKEY=<your-key>"

Scale Up/Out


az appservice plan update --name MyAppServicePlan \
    --resource-group MyResourceGroup \
    --sku S1

11. Common Deployment Issues and Solutions

IssueCauseSolution
502 Bad GatewayApp not respondingCheck logs in Kudu console
“The page cannot be displayed”Missing runtimeEnsure runtime version matches
Slow performanceInsufficient plan tierScale to higher SKU
Connection failureMissing environment variablesVerify app settings

12. Conclusion

Deploying web applications to Azure App Service provides developers with a powerful combination of simplicity, scalability, and security. It abstracts away the complexities of server management, allowing teams to focus purely on building great applications. With the ability to integrate CI/CD pipelines, monitor performance in real time, and scale automatically based on demand, Azure App Service is not just a hosting platform; it’s a foundation for continuous innovation and growth.

Through this guide, we’ve explored how to create and configure App Service resources using the Azure Portal, CLI, and C# SDK, along with deployment automation through Visual Studio and GitHub Actions. The examples demonstrate that Azure App Service adapts to various workflows — whether you prefer code-first automation or a visual approach. By combining these tools with Application Insights and App Settings management, you can maintain complete control over your application’s environment, performance, and security.

In essence, Azure App Service enables developers to bring ideas to life faster, deliver updates seamlessly, and ensure that applications remain available, responsive, and reliable, even under heavy workloads. As you continue building and deploying cloud-based applications, leveraging App Service’s integration with other Azure services (like Azure SQL, Key Vault, and Front Door) can take your architecture to the next level, ensuring that your web solutions are both modern and future-ready.