Skip to content
ASP.NET Core Reference & Cheatsheet

ASP.NET Core Reference & Cheatsheet

DodaTech Updated Jun 6, 2026 3 min read

Learning Path

    flowchart LR
    A["Aspnet Overview"] --> B["Core Concepts"]
    B --> C["Intermediate Topics"]
    C --> D["Advanced Topics"]
    D --> E["Practical Applications"]
    A --> F["You Are Here"]
    style F fill:#f90,color:#fff
  

A comprehensive reference for ASP.NET Core development — middleware pipeline, DI patterns, Entity Framework Core, controller conventions, and security best practices.

Program.cs Setup

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

Controller Example

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly AppDbContext _db;

    public ProductsController(AppDbContext db)
    {
        _db = db;
    }

    [HttpGet]
    public async Task<ActionResult<List<Product>>> GetAll()
    {
        return await _db.Products.ToListAsync();
    }

    [HttpGet("{id}")]
    public async Task<ActionResult<Product>> GetById(int id)
    {
        var product = await _db.Products.FindAsync(id);
        if (product == null) return NotFound();
        return product;
    }

    [HttpPost]
    public async Task<ActionResult<Product>> Create(Product product)
    {
        _db.Products.Add(product);
        await _db.SaveChangesAsync();
        return CreatedAtAction(nameof(GetById), new { id = product.Id }, product);
    }
}

Entity Framework Core

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int CategoryId { get; set; }
    public Category Category { get; set; }
}

public class AppDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<Category> Categories { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Product>()
            .Property(p => p.Price)
            .HasPrecision(18, 2);
    }
}

Middleware Pipeline Order

  1. Exception handling (UseExceptionHandler)
  2. HTTPS redirection (UseHttpsRedirection)
  3. Static files (UseStaticFiles)
  4. Routing (UseRouting)
  5. CORS (UseCors)
  6. Authentication (UseAuthentication)
  7. Authorization (UseAuthorization)
  8. Endpoints (MapControllers)

Dependency Injection

// Service lifetimes
builder.Services.AddScoped<IProductService, ProductService>();    // Per request
builder.Services.AddSingleton<ICacheService, MemoryCacheService>(); // Single instance
builder.Services.AddTransient<IEmailService, EmailService>();      // New each time

// Constructor injection
public class ProductService : IProductService
{
    private readonly AppDbContext _db;
    private readonly ILogger<ProductService> _logger;

    public ProductService(AppDbContext db, ILogger<ProductService> logger)
    {
        _db = db;
        _logger = logger;
    }
}

Common Configurations

// CORS
builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowFrontend", policy =>
        policy.WithOrigins("https://myapp.com")
              .AllowAnyHeader()
              .AllowAnyMethod());
});

// JWT Authentication
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidIssuer = builder.Configuration["Jwt:Issuer"],
            ValidAudience = builder.Configuration["Jwt:Audience"],
            IssuerSigningKey = new SymmetricSecurityKey(
                Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
        };
    });

Common Mistakes

  1. Assuming all features work identically — always check browser/version compatibility.
  2. Skipping documentation — reference docs exist for a reason; consult them.
  3. Not testing edge cases — your setup may differ from tutorials.
  4. Overlooking security — always validate inputs and follow best practices.
  5. Copy-pasting without understanding — type code yourself to build real knowledge.

What’s Next

LessonDescription
https://tutorials.dodatech.com/backend/nodejs/express/Express.js framework
https://tutorials.dodatech.com/backend/ror/reference/Ruby on Rails reference
C#C# programming language
.NET.NET platform overview
Entity FrameworkEF Core deep dive

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro