Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

69 posts
Getting started with RAG in ASP.NET Core

AI hype is everywhere, but where do you start with .NET? In this beginner-friendly post, we build a simple RAG pipeline in an ASP.NET Core Web API using keyword matching instead of embeddings, covering retrieve, augment, and generate end to end, with vector embeddings saved for a later post. ...

Building your first MCP server in ASP.NET Core

The Model Context Protocol (MCP) gives AI assistants a standardized way to interact with software. Learn how to construct your first MCP server in ASP.NET Core, expose C# tools using standard attributes, and test your setup end-to-end with the official MCP Inspector. ...

What happens when you call await? A step-by-step runtime breakdown

This step-by-step breakdown shows what happens when C# hits an await: the compiler generates an IAsyncStateMachine struct with a MoveNext() method splitting code at each await, using a GetDataCountAsync example with two awaited HttpClient calls to show how OnCompleted frees the calling thread. ...

Modern authentication in ASP.NET Core with 2FA and passkey

This walkthrough builds a .NET 10 ASP.NET Core Web API (TwoFaNET10) implementing two-factor authentication and WebAuthn/FIDO2 passkey login, using Microsoft.AspNetCore.Identity.EntityFrameworkCore with Npgsql PostgreSQL, JWT bearer tokens, and a custom ApplicationUser extending IdentityUser. ...

Simplifying file logging in ASP.NET Core with Serilog

Add file logging to an ASP.NET Core API with Serilog: configure the File sink, enable daily rolling logs, move settings to appsettings.json, control log levels, and enrich entries with machine name and user context. Includes a startup-exception logging example and production tips. ...

EF Core at scale: 5 ways to retrieve large datasets efficiently

Five EF Core bulk-fetch methods from Z.EntityFramework.Extensions that bypass the 2,100-parameter limit of .Contains: WhereBulkContains, WhereBulkNotContains, BulkRead, WhereBulkContainsFilterList, and WhereBulkNotContainsFilterList, benchmarked on a 1M-row PostgreSQL dataset. ...

Designing high-throughput APIs for 1M requests/minute .NET

Builds an ASP.NET Core Minimal API benchmarked with BenchmarkDotNet against a PostgreSQL Orders table, comparing a naive EF Core query using Include and Take(50000) against a raw Dapper query with pagination, indexing, and connection pooling to sustain 1M requests per minute. ...

How to upload files in an ASP.NET Core Web API

Shows how to build a file upload endpoint in a .NET 10 ASP.NET Core Web API using IFormFile and FileStream, add Swashbuckle.AspNetCore for OpenAPI/Swagger docs, cap uploads at 100 MB via MultipartBodyLengthLimit, and organize the code into clean, testable service layers with download support. ...

The complete guide to mastering Dapper micro-ORM in .NET

Walks through building a .NET console app that uses Dapper, the micro-ORM created by Stack Overflow, with Npgsql to query a PostgreSQL database of Movie and Director records, covering a DbConnectionFactory setup, JOINs, aggregate functions, stored procedures, and transactions. ...