Deploy ASP.NET Core
This guide will help you deploy an ASP.NET Core application to Deployxa.
Overview
ASP.NET Core is a cross-platform, high-performance framework for building modern, cloud-based applications. Deployxa provides optimized deployments for ASP.NET Core with automatic configuration.
Features:
- Automatic framework detection
- .NET 8+ support
- PostgreSQL, MySQL, SQL Server support
- Entity Framework Core
- Automatic HTTPS
- Global CDN
Prerequisites
- An ASP.NET Core application (.NET 8 recommended)
- A GitHub repository with your code
- A Deployxa account
Quick Start
1. Create Your ASP.NET Core App
If you don't have an ASP.NET Core app yet:
dotnet new webapi -n my-aspnet-app
cd my-aspnet-app
Or for MVC:
dotnet new mvc -n my-aspnet-app
cd my-aspnet-app
2. Configure for Production
Update appsettings.Production.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Host=${DB_HOST};Database=${DB_NAME};Username=${DB_USER};Password=${DB_PASSWORD}"
}
}
3. Push to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/my-aspnet-app.git
git push -u origin main
4. Deploy to Deployxa
- Go to Deployxa Dashboard
- Click "New Project"
- Select your GitHub repository
- Deployxa will automatically detect ASP.NET Core
- Click "Deploy"
Your app will be live in under 60 seconds!
Configuration
Detected Settings
Deployxa automatically detects these settings:
| Setting | Value |
|---|---|
| Framework | ASP.NET Core |
| Build Command | dotnet publish -c Release -o out |
| Output Directory | out |
| Start Command | dotnet out/*.dll |
| Port | 8080 |
Custom Configuration
If you need to customize settings:
- Go to Project → Settings → Build
- Modify settings as needed
- Save changes
Example Custom Settings:
{
"buildCommand": "dotnet publish -c Release -o out",
"outputDirectory": "out",
"startCommand": "dotnet out/MyApp.dll"
}
Environment Variables
Adding Environment Variables
- Go to Project → Environment
- Click "Add Variable"
- Enter key and value
- Click "Save"
Common ASP.NET Core Environment Variables:
ASPNETCORE_ENVIRONMENT=Production
ASPNETCORE_URLS=http://+:8080
# Database
DB_HOST=your-db-host
DB_NAME=your-database
DB_USER=your-username
DB_PASSWORD=your-password
# Connection String
ConnectionStrings__DefaultConnection=Host=${DB_HOST};Database=${DB_NAME};Username=${DB_USER};Password=${DB_PASSWORD}
Using Environment Variables
In your ASP.NET Core app:
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Access environment variable
var dbHost = Environment.GetEnvironmentVariable("DB_HOST");
// Or use configuration
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
var app = builder.Build();
app.Run();
// appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Host=${DB_HOST};Database=${DB_NAME};Username=${DB_USER};Password=${DB_PASSWORD}"
}
}
Database Configuration
Using PostgreSQL with Entity Framework Core
Add packages:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet add package Microsoft.EntityFrameworkCore.Design
Configure in Program.cs:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
Create models:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Create context:
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<User> Users { get; set; }
}
Database Migrations
Create initial migration:
dotnet ef migrations add InitialCreate
Apply migrations:
dotnet ef database update
Or in code:
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
}
Using MySQL
Add package:
dotnet add package Pomelo.EntityFrameworkCore.MySql
Configure:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(
builder.Configuration.GetConnectionString("DefaultConnection"),
ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("DefaultConnection"))
));
Custom Domains
Adding a Custom Domain
- Go to Project → Domains
- Click "Add Domain"
- Enter your domain (e.g.,
example.com) - Configure DNS records
- Wait for verification
DNS Configuration
For Apex Domain (example.com):
Type: A
Name: @
Value: 76.76.21.21
For Subdomain (www.example.com):
Type: CNAME
Name: www
Value: cname.deployxa.com
Performance Optimization
Enable Response Compression
Add package:
dotnet add package Microsoft.AspNetCore.ResponseCompression
Configure in Program.cs:
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
});
var app = builder.Build();
app.UseResponseCompression();
Enable Caching
Configure in Program.cs:
builder.Services.AddResponseCaching();
var app = builder.Build();
app.UseResponseCaching();
Use caching in controllers:
[ResponseCache(Duration = 60)]
[HttpGet]
public IActionResult GetData()
{
return Ok(data);
}
Database Connection Pooling
Entity Framework Core uses connection pooling by default. Configure in Program.cs:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString, sqlOptions =>
{
sqlOptions.MaxBatchSize(128);
}));
Monitoring
Viewing Logs
- Go to Project → Logs
- Select log type:
- Build Logs: Deployment process
- Runtime Logs: Application output
- Error Logs: Application errors
ASP.NET Core Logging
Configure logging in appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Use logging in code:
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
_logger.LogInformation("Home page accessed");
return View();
}
}
Health Checks
Add package:
dotnet add package Microsoft.AspNetCore.Diagnostics.HealthChecks
Configure in Program.cs:
builder.Services.AddHealthChecks();
var app = builder.Build();
app.MapHealthChecks("/health");
Monitoring Metrics
- Go to Project → Analytics
- View metrics:
- Request count
- Response times
- Error rates
- Bandwidth usage
- CPU/RAM usage
Troubleshooting
500 Internal Server Error
Problem: Application returns 500 error
Solution:
- Check runtime logs for errors
- Verify environment variables
- Check database connection
- Ensure application starts correctly
- Check for missing dependencies
Database Connection Failed
Problem: Npgsql.NpgsqlException or MySqlException
Solution:
- Verify connection string is correct
- Check database host and port
- Ensure database exists
- Check firewall rules
- Verify database credentials
Build Failed
Problem: dotnet publish fails
Solution:
- Check build logs for specific errors
- Verify dependencies are correct
- Check for syntax errors
- Test build locally
- Ensure .NET SDK version is compatible
Application Crashes on Start
Problem: Application crashes immediately
Solution:
- Check runtime logs for errors
- Verify environment variables
- Check for missing configuration
- Ensure ASPNETCORE_URLS is configured correctly
- Check for port conflicts
Slow Response Times
Problem: Application responds slowly
Solution:
- Enable response compression
- Use caching
- Optimize database queries
- Use async/await properly
- Upgrade plan for more resources
Best Practices
Project Structure
my-aspnet-app/
├── Controllers/
│ └── HomeController.cs
├── Models/
│ └── User.cs
├── Data/
│ └── ApplicationDbContext.cs
├── Migrations/
├── Views/
├── appsettings.json
├── appsettings.Production.json
├── Program.cs
├── my-aspnet-app.csproj
└── README.md
Environment Variables
- Never commit secrets
- Use
.env.exampleas template - Rotate secrets regularly
- Use different values per environment
Security
- Keep .NET updated
- Use HTTPS only
- Validate all inputs
- Use parameterized queries
- Enable CORS properly
- Use authentication/authorization
- Keep dependencies updated
Performance
- Enable response compression
- Use caching
- Optimize database queries
- Use async/await
- Use connection pooling
- Enable HTTP/2
Database
- Use migrations for schema changes
- Index frequently queried columns
- Use transactions for complex operations
- Backup database regularly
- Use connection pooling
Advanced Configuration
Custom Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddHealthChecks();
builder.Services.AddResponseCompression();
var app = builder.Build();
// Configure middleware
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseResponseCompression();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapHealthChecks("/health");
// Apply migrations
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
}
app.Run();
Docker Support
For local development with Docker:
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
API Versioning
Add package:
dotnet add package Asp.Versioning.Mvc
Configure:
builder.Services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
});
Examples
Basic ASP.NET Core App
// Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello, Deployxa!");
app.Run();
REST API
// Controllers/UsersController.cs
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
private readonly ApplicationDbContext _context;
public UsersController(ApplicationDbContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<User>>> GetUsers()
{
return await _context.Users.ToListAsync();
}
[HttpPost]
public async Task<ActionResult<User>> CreateUser(User user)
{
_context.Users.Add(user);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetUsers), new { id = user.Id }, user);
}
}
With Database
// Data/ApplicationDbContext.cs
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<User> Users { get; set; }
}
// Models/User.cs
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Related Topics
Resources
Need Help? Contact support@deployxa.com or join our community Discord.