Deploying to Azure for Free
Intermediate
25 min read
Lesson 3 of 5
Why Choose Azure?
Microsoft Azure offers a comprehensive free tier that allows you to host web applications, databases, and other services at no cost. It's an excellent choice for learning and prototyping.
Azure Free Account Benefits
- 12 months of free services
- $200 credit for the first 30 days
- 25+ services always free
- No credit card required to start
Step 1: Create Azure Account
1Visit Azure Portal
Go to azure.microsoft.com/free
2Sign Up
Click "Start free" and create your account using a Microsoft account or email.
3Verification
Verify your identity with a phone number and credit card (for verification only, no charges).
Step 2: Create App Service
// Using Azure Portal
1. Sign in to Azure Portal
2. Click "Create a resource"
3. Search for "Web App"
4. Click "Create"
5. Configure your app:
- Subscription: Your free subscription
- Resource Group: Create new (e.g., "MyAppRG")
- Name: Unique app name (e.g., "myapp2024")
- Publish: Code
- Runtime stack: .NET 10 (or your version)
- Operating System: Windows/Linux
- Region: Choose closest to users
- App Service Plan: Free F1 tier
6. Click "Review + create"
Step 3: Deploy Using Visual Studio
// Method 1: Publish from Visual Studio
1. Right-click your project in Solution Explorer
2. Select "Publish"
3. Choose "Azure" and "Azure App Service"
4. Select your subscription and app service
5. Click "Publish"
// Method 2: Using CLI
// Install Azure CLI
dotnet tool install -g Microsoft.Azure.WebJobs.Extensions.Functions
// Login to Azure
az login
// Deploy
az webapp deploy --resource-group MyAppRG --name myapp2024 --src-path ./publish
Step 4: Deploy Using GitHub Actions
// Create .github/workflows/azure-deploy.yml
name: Deploy to Azure
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '10.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Publish
run: dotnet publish -c Release -o ./publish
- name: Deploy to Azure
uses: azure/webapps-deploy@v2
with:
app-name: myapp2024
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
Step 5: Configure Database
// Azure SQL Database - Free Tier
1. Create Azure SQL Database
2. Choose the free tier (Basic tier)
3. Create database server and firewall rules
4. Get connection string
// Connection string in appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=tcp:yourserver.database.windows.net,1433;Database=mydb;User ID=youruser;Password=yourpassword;"
}
}
// Use Azure Key Vault for production secrets
// Store connection strings in Azure Key Vault
Step 6: Configure Application Settings
// In Azure Portal
1. Go to your App Service
2. Click "Configuration"
3. Add application settings:
- ConnectionStrings:DefaultConnection = your production connection string
- Environment = Production
- Logging:LogLevel:Default = Error
// Access in code
var connectionString = Configuration.GetConnectionString("DefaultConnection");
var environment = Configuration["Environment"];
Step 7: Enable Logging and Monitoring
// Enable Application Insights
1. Add Application Insights to your project
2. Configure in appsettings.json
3. View logs in Azure Portal
// Configure logging
builder.Logging.AddAzureWebAppDiagnostics();
// In Program.cs
if (app.Environment.IsProduction())
{
app.UseApplicationInsights();
}
Step 8: Domain and SSL
// Custom Domain Configuration
1. Go to your App Service
2. Click "Custom domains"
3. Add your custom domain
4. Verify domain ownership
// SSL Configuration
1. Azure provides free SSL certificates
2. Enable HTTPS Only in your app service
3. Configure TLS/SSL settings
Complete Azure Deployment Checklist
Azure Deployment Checklist
- ✅ Create Azure free account
- ✅ Create App Service with Free tier
- ✅ Create Azure SQL Database
- ✅ Configure connection strings
- ✅ Deploy using Visual Studio or CLI
- ✅ Set up GitHub Actions for CI/CD
- ✅ Configure application settings
- ✅ Enable logging and monitoring
- ✅ Set up custom domain
- ✅ Enable HTTPS and SSL
- ✅ Test application in production
- ✅ Monitor performance and errors
Key Takeaway
Azure provides a robust free tier for hosting ASP.NET Core applications. With proper configuration, you can deploy production-ready applications at no cost.
Exercise
Deploy your application to Azure:
- Create Azure free account
- Create App Service with Free tier
- Deploy your application
- Configure database connection
- Set up custom domain (optional)
- Monitor application performance