Have you ever tried to read the HttpContext.Request.Body in a middleware or a filter, only to find that your API controller receives an empty body? Or worse, your application crashes? By default, the request body is a forward-only stream. Once it’s read, the pointer reaches the end, and there’s nothing left for the next component […]
Author: ErcanOPAK
ASP.NET Core “Response Compression Not Working” — The Missing MIME Types
Compression silently fails without explicit MIME config. ✅ Fix builder.Services.AddResponseCompression(options => { options.MimeTypes = ResponseCompressionDefaults.MimeTypes .Concat(new[] { “application/json” }); });
SQL “DELETE Is Slow” — Use Batch Deletes
Deleting millions of rows at once is dangerous. ❌ DELETE FROM Logs WHERE CreatedAt < ‘2023-01-01’; ✅ Safe Batch Delete WHILE 1 = 1 BEGIN DELETE TOP (1000) FROM Logs WHERE CreatedAt < ‘2023-01-01’; IF @@ROWCOUNT = 0 BREAK; END Why Avoids log explosion Prevents long locks
SQL “TOP 1 WITH ORDER BY” Without Index = Full Scan
This query is slow without the right index: SELECT TOP 1 * FROM Orders ORDER BY CreatedAt DESC; ✅ Correct Index CREATE INDEX IX_Orders_CreatedAt ON Orders (CreatedAt DESC); Result Instant response No table scan
C# Boxing Kills Performance (Without You Noticing)
This looks harmless: List<object> list = new(); list.Add(5); // boxing ✅ Fix Use generics: List<int> list = new(); Why it matters Boxing allocates memory GC pressure increases fast in loops
C# “Lock Contention” — Why lock(this) Breaks Apps
This is dangerous: lock(this) { // critical section } ❌ Why it fails External code can also lock on this Deadlocks appear randomly ✅ Correct Pattern private readonly object _sync = new(); lock (_sync) { // safe }
C# Async Streams — Stop Loading Huge Lists Into Memory
If you return large datasets like this: var data = await repository.GetAllAsync(); You already lost memory and latency. ✅ Stream Instead await foreach (var item in repository.StreamAsync()) { Process(item); } Why this is life-saving Near-zero memory footprint Faster first byte Perfect for logs, exports, ETL
Visual Studio “F5 Takes Forever” — IIS Express Cache
✅ Fix Delete: .vs/ Then restart Visual Studio. Why IIS Express config cache becomes corrupted.
WordPress Slow First Load — Autoloaded Options Table
Run this: SELECT * FROM wp_options WHERE autoload = ‘yes’; Too many rows = slow site. ✅ Fix Disable autoload on unused options. This alone can cut TTFB in half.
Windows 11 Laptop Overheats — Turbo Boost Gone Wrong
Turbo Boost causes thermal throttling loops. ✅ Fix Limit max CPU to 99%: Power Options → Processor → Maximum Processor State → 99% Why Disables Turbo without killing performance.
Windows 11 Slow Context Menu — The Explorer Extension Trap
Third-party shell extensions slow everything. ✅ Fix Disable non-Microsoft extensions using ShellExView. Result Instantly faster right-click menus.
AJAX “Works Once, Then Fails” — Cached POST Response
Some browsers cache aggressively. ✅ Fix fetch(url, { method: ‘POST’, cache: ‘no-store’ }); Especially important for forms authentication dynamic APIs
JS Memory Leaks — Forgotten Event Listeners
Single-page apps suffer badly from this. ❌ window.addEventListener(‘resize’, handler); ✅ window.removeEventListener(‘resize’, handler); Always clean up listeners on unmount or destroy.
HTML5 button Defaults to submit (Surprise!)
This causes accidental form submissions. ❌ <button>Click</button> ✅ <button type=”button”>Click</button> Rule Always set the button type explicitly.
CSS opacity Breaks Child Elements — Use RGBA Instead
❌ .card { opacity: 0.8; } This also fades text and icons. ✅ .card { background-color: rgba(0,0,0,0.8); } Why Opacity affects the entire element tree.
ASP.NET Core Health Checks That Actually Matter
Many health checks always return OK. ❌ Useless services.AddHealthChecks(); ✅ Useful services.AddHealthChecks() .AddSqlServer(conn) .AddRedis(redisConn); Why Kubernetes and load balancers rely on this.
ASP.NET Core “Slow Startup” — Reflection Scanning Trap
Large projects often scan assemblies repeatedly. ✅ Fix Disable automatic scanning where possible and register explicitly: services.AddScoped<IService, Service>(); Why Reflection is slow at startup — especially in containers.
SQL SELECT * — The Hidden Future Bug
Works today, breaks tomorrow. ❌ SELECT * FROM Users; ✅ SELECT Id, Name, Email FROM Users; Why Schema changes break consumers Pulls unnecessary data Slower network and memory usage
SQL “Index Fragmentation Panic” — When NOT to Rebuild
Many rebuild indexes blindly. ❌ Bad Habit ALTER INDEX ALL ON Orders REBUILD; ✅ Smart Rule Fragmentation < 5% → do nothing 5–30% → REORGANIZE 30% → REBUILD ALTER INDEX IX_Orders_Date ON Orders REORGANIZE; Why Rebuild = blocking + log growth.
C# Exception Handling — The Silent Performance Killer
Exceptions are expensive.They are not flow control. ❌ try { return dict[key]; } catch { return null; } ✅ return dict.TryGetValue(key, out var value) ? value : null; Rule If it can fail often → do NOT use exceptions.
C# “foreach Is Slower Than for” — Yes, Sometimes
On List<T> this matters in tight loops. ❌ foreach (var item in list) { } ✅ Faster for (int i = 0; i < list.Count; i++) { } Why foreach creates an enumerator for is index-based and faster Use this only in hot paths, not everywhere.
C# Span — The Secret to Zero-Allocation Performance
If you manipulate strings or byte arrays heavily, this matters. ❌ Common Allocation Trap var part = input.Substring(0, 10); ✅ Zero-Allocation Alternative ReadOnlySpan<char> part = input.AsSpan(0, 10); Why this is huge No heap allocation No GC pressure Perfect for parsers and hot paths
Visual Studio High CPU When Idle? Live Code Analysis
Background analyzers can eat CPU. ✅ Fix Disable unused analyzers: Tools → Options → Text Editor → C# → Advanced Turn off: Full solution analysis
WordPress Slow Admin Panel? Heartbeat API
WordPress sends frequent AJAX calls. ✅ Fix Install Heartbeat ControlReduce frequency or disable in admin. Result Faster editor Lower CPU usage
Windows 11 Micro-Stutters in Apps? Disable MPO
Multi-Plane Overlay causes flickering and stutter. ✅ Fix (Registry) DisableMPO = 1 (Path: GraphicsDrivers)
Windows 11 Laptop Slow on Battery? CPU Throttling
Windows limits CPU aggressively. ✅ Fix powercfg /setactive SCHEME_MIN Or switch to Best Performance power mode.
AJAX Requests Fail Randomly? CSRF Token Missing
POST requests fail silently without CSRF token. ✅ Fix headers: { ‘X-CSRF-TOKEN’: token } Common victims Laravel Django ASP.NET MVC
JS “await” Inside forEach Is a Bug
This does NOT work: items.forEach(async item => { await process(item); }); ✅ Correct Patterns for (const item of items) { await process(item); } or parallel: await Promise.all(items.map(process));
HTML5 Lazy Loading Without JavaScript
Stop writing JS for images. <img src=”image.jpg” loading=”lazy” /> Benefits Faster page load Better Core Web Vitals Zero JavaScript
CSS 100vh Is Broken on Mobile (Real Fix)
height: 100vh breaks on mobile browsers. ✅ Correct Solution height: 100dvh; Or fallback: min-height: -webkit-fill-available; Why Mobile address bars change viewport height dynamically.








