NET Centric ComputingUnit 106 min read

Hosting & Deploying ASP.NET Core: Servers, Clouds, CI/CD & Monitoring

Unit 10 of NET Centric Computing covers the end-to-end process of deploying ASP.NET Core applications—choosing hosting environments (IIS, Linux, containers), configuring cloud platforms (Azure, AWS, Google Cloud), automating CI/CD pipelines, and monitoring live applications with tools like Application Insights and Prom

Core Concepts

What is Hosting?

Hosting refers to the service that makes your ASP.NET Core application accessible to users over the internet. It involves:

  • Server infrastructure: Physical or virtual machines that run your app.
  • Networking: DNS, load balancers, and firewalls to ensure availability.
  • Scalability: Ability to handle increased traffic by adding resources.
classDiagram
    class HostingEnvironment {
        +IIS (Windows)
        +Nginx/Apache (Linux)
        +Docker Containers
        +Cloud Platforms (Azure/AWS)
    }
    class DeploymentSteps {
        +Build Artifacts
        +Configure Server
        +Deploy Code
        +Test & Monitor
    }
    HostingEnvironment --> DeploymentSteps : "Requires"

Choosing a Hosting Environment

Option Best For Pros Cons
IIS (Windows) Traditional Windows apps, legacy DBs Native .NET support, easy setup Less scalable, Windows-only
Linux (Nginx/Apache) High-performance, cost-effective Faster, cheaper, supports Docker Requires Linux expertise
Docker Containers Microservices, scalable apps Portable, isolated, easy scaling Complex setup, requires Kubernetes for orchestration
Cloud (Azure/AWS) Global reach, auto-scaling Pay-as-you-go, managed services Vendor lock-in, cost at scale

Real-World Example:

  • eSewa uses cloud hosting (likely AWS or Azure) to handle thousands of transactions per second during festival seasons. Their ASP.NET Core backend is deployed in auto-scaling containers to manage traffic spikes.

Deployment Workflow

  1. Build Artifacts: Compile your ASP.NET Core app into a deployable format (e.g., publish folder).
  2. Configure Server: Set up the hosting environment (e.g., install .NET runtime, configure IIS/Nginx).
  3. Deploy Code: Use tools like:
    • Kudu (Azure Web Apps)
    • GitHub Actions (CI/CD)
    • Docker Compose (containerized apps)
  4. Test & Monitor: Verify functionality and set up logging/monitoring.

Cloud Hosting Platforms

Azure App Service

  • Best for: Quick deployment, managed services (SQL, caching).
  • Key Features:
    • Auto-scaling based on traffic.
    • Built-in CI/CD with GitHub/Azure DevOps.
    • Supports Windows/Linux containers.

Example:

  • Ncell’s customer portal (if built with ASP.NET Core) likely uses Azure App Service for its reliability and integration with Microsoft tools.

AWS Elastic Beanstalk

  • Best for: Highly scalable apps with AWS ecosystem.
  • Key Features:
    • Supports .NET Core via Docker or PaaS.
    • Integrates with RDS (databases), S3 (storage), and CloudWatch (monitoring).

Example:

  • Daraz’s backend services (if using .NET) might leverage AWS Elastic Beanstalk for global scalability during sales events.

Google Cloud Run

  • Best for: Serverless, event-driven apps.
  • Key Features:
    • Scales to zero when idle (cost-effective).
    • Supports Docker containers natively.

CI/CD for ASP.NET Core

Continuous Integration/Deployment automates testing and deployment. Tools:

  • GitHub Actions: Trigger builds on code push.
  • Azure DevOps: Pipeline for Azure-hosted apps.
  • Jenkins: Open-source CI/CD server.

Example Workflow for a Bank Loan App:

  1. Developer pushes code to GitHub.
  2. GitHub Actions runs unit tests.
  3. If tests pass, deploy to a staging server (e.g., Azure).
  4. Manual approval → deploy to production.
sequenceDiagram
    Developer->>GitHub: Push Code
    GitHub->>GitHub Actions: Trigger Build
    GitHub Actions->>Azure: Run Tests
    Azure-->>GitHub Actions: Test Results
    GitHub Actions->>Staging: Deploy (if passed)
    Staging->>QA: Manual Testing
    QA-->>Production: Approve
    Production->>Users: Release

Monitoring and Logging

Tools to track app health:

Tool Purpose Example Use Case
Application Insights Performance metrics, logs Track response times in a Pathao order system
Prometheus + Grafana Custom metrics, dashboards Monitor NTC’s network traffic in real-time
ELK Stack (Elasticsearch, Logstash, Kibana) Log aggregation Debug issues in a Daraz checkout flow

Security in Deployment

  1. HTTPS: Enforce SSL/TLS (e.g., Let’s Encrypt for free certificates).
  2. Secrets Management: Use Azure Key Vault or AWS Secrets Manager for appsettings.json keys.
  3. Network Security:
    • Restrict access via firewalls (e.g., Azure NSG).
    • Use private endpoints for databases.

Example:

  • Khalti’s payment gateway uses HTTPS and secrets management to secure transaction data during deployments.

Cost Optimization

  • Reserved Instances: Commit to 1/3-year terms for cloud VMs (e.g., AWS Reserved Instances).
  • Spot Instances: Use for non-critical workloads (e.g., batch processing).
  • Serverless: Pay only for execution time (e.g., Azure Functions).

Exam Tip

  1. Hosting Environments: Know the pros/cons of IIS, Linux, Docker, and cloud. Expect a comparison question.
  2. Deployment Steps: Memorize the workflow (Build → Test → Deploy → Monitor).
  3. Cloud Platforms: Focus on Azure App Service and AWS Elastic Beanstalk for ASP.NET Core.
  4. CI/CD: Understand GitHub Actions/Azure DevOps pipelines. A diagram-based question is likely.
  5. Monitoring: Application Insights is key—know how to set up alerts for errors or slow responses.
  6. Security: Always mention HTTPS, secrets management, and network restrictions in deployment answers.

Real-World Tie-In:

  • NEPSE’s trading platform (if built with ASP.NET Core) uses cloud hosting (likely Azure) for 24/7 availability. Their CI/CD pipeline ensures zero downtime during market hours, and Application Insights monitors trade execution latency. During Diwali, auto-scaling handles 3x traffic, while secrets management protects API keys for broker integrations.

Based on the TU BIT syllabus for NET Centric Computing (BIT351), unit 10.

Discussion

Loading…