Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: Asp.Net Core

Asp.Net Core

.NET Core — UseDeveloperExceptionPage in Production Is Dangerous

- 28.12.25 - ErcanOPAK comment on .NET Core — UseDeveloperExceptionPage in Production Is Dangerous

Leaks: stack traces internal paths config values ✅ Rule Enable only in Development.

Read More
Asp.Net Core

.NET Core — Model Validation Runs Before Your Code

- 28.12.25 - ErcanOPAK comment on .NET Core — Model Validation Runs Before Your Code

Even before controller logic. 🧠 Why it matters Expensive validations slow APIs Happens on every request ✅ Tip Keep DTOs small and flat.

Read More
Asp.Net Core

Performance — Measuring in Dev Lies to You

- 28.12.25 - ErcanOPAK comment on Performance — Measuring in Dev Lies to You

Local machines hide: IO waits CPU contention GC pressure ✅ Rule Benchmark under production-like load.

Read More
Asp.Net Core

Security — URL Length Can Kill Requests

- 28.12.25 - ErcanOPAK comment on Security — URL Length Can Kill Requests

Browsers & proxies limit URL size. ❌ Breaks Large GET filters Search queries ✅ Fix Use POST for complex payloads.

Read More
Asp.Net Core

HTTP — Caching Is Disabled More Often Than You Think

- 28.12.25 - ErcanOPAK comment on HTTP — Caching Is Disabled More Often Than You Think

No cache headers = slower everything. ✅ Add ETag Cache-Control If-None-Match Result: fewer bytes, faster pages, happier users.

Read More
Asp.Net Core / C#

.NET Core — Request Aborted Token Is Ignored Too Often

- 27.12.25 - ErcanOPAK comment on .NET Core — Request Aborted Token Is Ignored Too Often

Client disconnects — server keeps working. ✅ Fix Use: HttpContext.RequestAborted Cancel long-running operations immediately.

Read More
Asp.Net Core / C#

.NET Core — Async Controllers Can Still Block Threads

- 27.12.25 - ErcanOPAK comment on .NET Core — Async Controllers Can Still Block Threads

Async does NOT guarantee non-blocking. ❌ Hidden blocker Task.Result Task.Wait() ✅ Rule Async all the way — no sync-over-async.

Read More
Asp.Net Core

.NET Core — Logging Too Much Can DOS Your Own App

- 25.12.25 - ErcanOPAK comment on .NET Core — Logging Too Much Can DOS Your Own App

Excessive logging is a performance bug. ❌ Symptoms Disk IO spikes Thread pool starvation ✅ Rule Log events, not flows.

Read More
Asp.Net Core

.NET Core — Kestrel Has Request Limits You Might Hit

- 25.12.25 - ErcanOPAK comment on .NET Core — Kestrel Has Request Limits You Might Hit

Large uploads fail silently. Default limits Request body size Header count Header length ✅ Fix Explicitly configure limits in Kestrel.

Read More
Asp.Net Core / C#

.NET Core — Response Compression Isn’t Enabled by Default

- 21.12.25 - ErcanOPAK comment on .NET Core — Response Compression Isn’t Enabled by Default

Many APIs forget this. builder.Services.AddResponseCompression(); app.UseResponseCompression(); Result Smaller payloads Faster mobile clients Lower bandwidth costs

Read More
Asp.Net Core / C#

.NET Core — MapGroup() for API Versioning Without Pain

- 21.12.25 - ErcanOPAK comment on .NET Core — MapGroup() for API Versioning Without Pain

var v1 = app.MapGroup(“/api/v1”); v1.MapGet(“/users”, GetUsers); Benefits Cleaner routing Shared filters & auth Scales beautifully

Read More
Asp.Net Core / C#

Request Body Can Only Be Read Once

- 19.12.25 - ErcanOPAK comment on Request Body Can Only Be Read Once

Middleware reading body breaks controllers. ✅ Fix Enable buffering: context.Request.EnableBuffering(); Then rewind stream.

Read More
Asp.Net Core / C#

Scoped Services Inside Singleton = Time Bomb

- 19.12.25 - ErcanOPAK comment on Scoped Services Inside Singleton = Time Bomb

public class MySingleton { public MySingleton(MyScopedService s) { } } ❌ Problem Captures first request scope forever Causes stale data & memory leaks ✅ Fix Use IServiceScopeFactory.

Read More
Asp.Net Core

Model Binding Is Slower Than You Think

- 17.12.25 - ErcanOPAK comment on Model Binding Is Slower Than You Think

Large request models cost CPU. ✅ Optimization Use [FromBody] DTOs instead of giant domain models. Why Less reflection Faster deserialization Cleaner APIs

Read More
Asp.Net Core

IOptionsSnapshot vs IOptionsMonitor — Subtle but Critical

- 17.12.25 - ErcanOPAK comment on IOptionsSnapshot vs IOptionsMonitor — Subtle but Critical

Wrong choice causes stale configs or memory leaks. IOptionsSnapshot → per request IOptionsMonitor → real-time updates ✅ Rule Use Monitor only if config changes at runtime.

Read More
Asp.Net Core

IHostedService vs BackgroundService

- 17.12.25 - ErcanOPAK comment on IHostedService vs BackgroundService

Many misuse them. 🧠 Difference IHostedService = lifecycle hooks BackgroundService = long-running loops ✅ Rule Use BackgroundService for workers.

Read More
Asp.Net Core / C#

Middleware Order Can Break Security

- 17.12.25 - ErcanOPAK comment on Middleware Order Can Break Security

Order matters a lot. ❌ Wrong UseEndpoints(); UseAuthentication(); ✅ Correct UseAuthentication(); UseAuthorization(); UseEndpoints();  

Read More
Asp.Net Core / C#

HttpClient Socket Exhaustion — Still Happening in 2025

- 16.12.25 - ErcanOPAK comment on HttpClient Socket Exhaustion — Still Happening in 2025

This is wrong: new HttpClient(); ✅ Correct builder.Services.AddHttpClient(); Why Reuses sockets Prevents random timeouts

Read More
Asp.Net Core / C#

Minimal APIs — Why Filters Replace Middleware

- 16.12.25 - ErcanOPAK comment on Minimal APIs — Why Filters Replace Middleware

Middleware runs for every request. ✅ Endpoint Filter app.MapPost(“/orders”, handler) .AddEndpointFilter<AuthFilter>(); Why Faster Scoped Cleaner

Read More
Asp.Net Core / C#

ASP.NET Core “Request Body Already Read” — Enable Buffering

- 15.12.25 | 16.01.26 - ErcanOPAK comment on ASP.NET Core “Request Body Already Read” — Enable Buffering

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 […]

Read More
Asp.Net Core / C#

ASP.NET Core “Response Compression Not Working” — The Missing MIME Types

- 15.12.25 - ErcanOPAK comment on 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” }); });  

Read More
Asp.Net Core / C#

ASP.NET Core Health Checks That Actually Matter

- 14.12.25 - ErcanOPAK comment on 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.

Read More
Asp.Net Core / C#

ASP.NET Core “Slow Startup” — Reflection Scanning Trap

- 14.12.25 - ErcanOPAK comment on 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.

Read More
Asp.Net Core / C#

ASP.NET Core Thread Pool Starvation Explained

- 13.12.25 - ErcanOPAK comment on ASP.NET Core Thread Pool Starvation Explained

Symptoms: Random timeouts CPU low but requests hang Root cause Blocking calls inside async code: Task.Delay(1000).Wait(); ✅ Fix await Task.Delay(1000); Rule Never block threads in ASP.NET.

Read More
Asp.Net Core / C#

ASP.NET Core Logging Slows Your API (Yes, Really)

- 13.12.25 - ErcanOPAK comment on ASP.NET Core Logging Slows Your API (Yes, Really)

This is expensive: _logger.LogInformation($”User {id} logged in”); ✅ Correct Way _logger.LogInformation(“User {UserId} logged in”, id); Why Avoids string interpolation Enables structured logging Reduces allocations

Read More
Asp.Net Core / C#

.NET Core “Configuration Not Updating” — Missing ReloadOnChange

- 12.12.25 - ErcanOPAK comment on .NET Core “Configuration Not Updating” — Missing ReloadOnChange

If you update appsettings.json in production and nothing changes… ✔ Fix builder.Configuration.AddJsonFile( “appsettings.json”, optional: false, reloadOnChange: true ); 💡 Bonus Works even in Kubernetes (mounted config map).

Read More
Asp.Net Core / C#

ASP.NET Core “Middleware Never Executes” — The Ordering Trap

- 12.12.25 - ErcanOPAK comment on ASP.NET Core “Middleware Never Executes” — The Ordering Trap

If you place middleware in the wrong order → it silently does nothing. ❌ Wrong app.UseEndpoints(…); app.UseAuthentication(); ✔ Correct app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(…); 💡 Golden Rule Auth must come BEFORE endpoints.

Read More
Asp.Net Core / C#

.NET Core “HttpClient Exhaustion” — Why Your API Suddenly Stops Responding

- 11.12.25 - ErcanOPAK comment on .NET Core “HttpClient Exhaustion” — Why Your API Suddenly Stops Responding

Most devs know not to use new HttpClient(),but they forget the REAL killer: DNS caching. Containers change DNS → HttpClient reuses stale DNS forever. ✔ Fix Use SocketsHttpHandler.PooledConnectionIdleTimeout: builder.Services.AddHttpClient(“api”) .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2) }); Prevents DNS poisoning.

Read More
Asp.Net Core

ASP.NET Core “Random 404 After Deploy” — Broken Routing Cache

- 11.12.25 - ErcanOPAK comment on ASP.NET Core “Random 404 After Deploy” — Broken Routing Cache

Kestrel caches endpoints.When you add a new route but deploy without clearing the build output → ghost routes happen. ✔ Fix Add this to .csproj: <PropertyGroup> <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> </PropertyGroup> Ensures routes rebuild properly every deploy.

Read More
Asp.Net Core / C#

.NET Core “Kestrel Timeout” — The Hidden Request Body Limit

- 09.12.25 - ErcanOPAK comment on .NET Core “Kestrel Timeout” — The Hidden Request Body Limit

Many APIs fail mysteriously with: “Unexpected end of request content.” Because the request body timeout is too low. ✔ Fix builder.WebHost.ConfigureKestrel(o => { o.Limits.RequestBodyTimeout = TimeSpan.FromMinutes(5); }); 💡 Life-Saver For: file uploads slower mobile clients integrations with old systems

Read More
Page 5 of 7
« Previous 1 2 3 4 5 6 7 Next »

Posts navigation

Older posts
Newer posts
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (754)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com