Many misuse them. đź§ Difference IHostedService = lifecycle hooks BackgroundService = long-running loops âś… Rule Use BackgroundService for workers.
Author: ErcanOPAK
Middleware Order Can Break Security
Order matters a lot. ❌ Wrong UseEndpoints(); UseAuthentication(); ✅ Correct UseAuthentication(); UseAuthorization(); UseEndpoints();
NOT IN vs NOT EXISTS — One Can Return Wrong Results
WHERE Id NOT IN (SELECT UserId FROM BannedUsers) ❌ Problem If subquery returns NULL, results are wrong. ✅ Always Safer WHERE NOT EXISTS ( SELECT 1 FROM BannedUsers b WHERE b.UserId = u.Id )
SELECT * Breaks Index Usage
This kills performance: SELECT * FROM Orders đź§ Why Forces key lookups Breaks covering indexes âś… Fix Select only what you need: SELECT Id, Total FROM Orders
Structs Aren’t Always Faster Than Classes
Many devs assume structs = faster. ❌ Reality Large structs copy memory Passed by value by default ✅ Rule of Thumb Small, immutable → struct Complex objects → class
LINQ ToList() — The Performance Trap
This line is expensive: var users = query.ToList(); đź§ Why Executes immediately Loads everything into memory âś… Better Stream or filter first: var users = query.Where(x => x.IsActive);
async void — The Exception Black Hole
This should almost never exist: async void DoWork() ❌ Why it’s dangerous Exceptions crash the process Cannot be awaited Impossible to test ✅ Correct async Task DoWorkAsync() Only valid use: event handlers.
Visual Studio Debugger Skips Lines — Optimized Build Trap
Debugger lies when optimization is on. ✅ Fix Build Configuration → DebugDisable Optimize Code
WordPress Admin Slow — Heartbeat API Overload
Heartbeat runs every 15s. âś… Fix Reduce frequency or disable on non-edit pages. Result Lower CPU Faster admin
SSD Slow on Windows 11 — TRIM Disabled
Check: fsutil behavior query DisableDeleteNotify 0 = enabled1 = disabled (bad)
Windows 11 Random Freezes — Power Plan Trap
Balanced mode throttles CPUs aggressively. ✅ Fix Power Settings → High Performance
Silent AJAX Failures — Missing Content-Type
Backend never hits controller? âś… Fix headers: { “Content-Type”: “application/json” }
forEach + async — A Hidden Logic Bug
This does not await: array.forEach(async x => await save(x)); âś… Fix for (const x of array) { await save(x); }
loading=”lazy” — Free Performance Win
<img src=”hero.jpg” loading=”lazy”> Why Faster initial load Lower bandwidth Better Core Web Vitals
100vh Breaks Mobile Layouts — Here’s Why
Mobile browsers resize viewport dynamically. âś… Fix height: 100svh; or JS-calculated height.
HttpClient Socket Exhaustion — Still Happening in 2025
This is wrong: new HttpClient(); âś… Correct builder.Services.AddHttpClient(); Why Reuses sockets Prevents random timeouts
Minimal APIs — Why Filters Replace Middleware
Middleware runs for every request. âś… Endpoint Filter app.MapPost(“/orders”, handler) .AddEndpointFilter<AuthFilter>(); Why Faster Scoped Cleaner
Missing WHERE on UPDATE — Disaster Prevention Trick
Human error happens. âś… Safety Pattern BEGIN TRAN UPDATE Users SET IsActive = 0 WHERE LastLogin < ‘2022-01-01’ — sanity check SELECT @@ROWCOUNT ROLLBACK
Parameter Sniffing — The Query That Works… Until It Doesn’t
Same query, different performance. đź§ Root cause SQL caches execution plans based on the first parameter. âś… Fix Options OPTION (RECOMPILE) or OPTIMIZE FOR UNKNOWN
ValueTask — Faster but Dangerous
ValueTask<int> GetAsync(); âš Hidden traps Cannot await twice Harder debugging âś… Rule Use only when result is usually synchronous.
ConfigureAwait(false) — When It Actually Matters
Using it everywhere is wrong. ✅ Use it when: Library code No UI / request context needed await httpClient.GetAsync(url) .ConfigureAwait(false); ❌ Avoid in: ASP.NET Core (no sync context) UI event handlers
Task.Run() in ASP.NET — The Silent Scalability Killer
This looks harmless: Task.Run(() => DoWork()); ❌ Why it breaks production Bypasses request lifecycle Ignores cancellation Starves thread pool under load ✅ Correct Pattern Use background services: public class Worker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) await DoWorkAsync(ct); } }
Visual Studio “IntelliSense Wrong Types” — Stale Solution Cache
Types show incorrectly? Suggestions are wrong? ✅ Fix Close VS and delete: .vs/ bin/ obj/ Reopen solution → fixed.
WordPress REST API Slow — Disable Unused Endpoints
Every REST route loads on init. âś… Fix Disable what you don’t use via plugin or code: remove_action(‘rest_api_init’, ‘wp_oembed_register_route’); Result Lower memory usage and faster responses.
Windows 11 Laptop Fans Always Loud — Background Indexing
Search indexing runs aggressively on SSDs. ✅ Fix Settings → Privacy → Searching Windows → Reduce indexing scope.
Windows 11 Slow Boot After Updates — Startup App Priority
Windows sometimes re-enables heavy startup apps. ✅ Fix Task Manager → Startup → Disable non-essential apps. Result Faster boot and login.
AJAX Requests Timeout Randomly — Browser Connection Limits
Browsers limit concurrent connections per domain. âś… Fix Throttle requests or queue them: await Promise.allSettled(queue.map(run)); Especially important for dashboards batch uploads
JS “Undefined Is Not Null” — The Bug That Breaks APIs
undefined !== null âś… Defensive Check if (value == null) { // catches both null and undefined } Use strict checks only when you really need them.
HTML5 autocomplete — Stop Browsers From Guessing Wrong
Browsers often autofill incorrect data. âś… Control It <input name=”email” autocomplete=”email”> <input name=”one-time-code” autocomplete=”one-time-code”> Why Improves UX and security.
CSS position: sticky Not Working? Here’s Why
Sticky fails when parent has: overflow: hidden; âś… Fix Remove overflow or move sticky element higher in the DOM. Sticky only works inside scrollable ancestors.








