Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Build, debug, modernize, or review ASP.NET Core applications with correct hosting, middleware, security, configuration, logging, and deployment patterns on current .NET. USE FOR: working on ASP.NET Core apps, services, or middleware; changing auth, routing, configuration, hosting, or deployment behavior; deciding between ASP.NET Core sub-stacks. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files, a
.claude/skills/managedcode-aspnet-core/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 42% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 51% | 0% |
| case-16 | ✓→✓ | = Same ✓ | 102% | 0% |
| case-22 | ✓→✓ | = Same ✓ | 119% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 74% | 0% |
Program.cs structure ExceptionHandler → HttpsRedirection → Static Files → Routing → CORS → Authentication → Authorization → Rate Limiting → Response Caching → Custom Middleware → Endpoints
IOptions<T> / IOptionsSnapshot<T> for configurationILogger<T> for structured loggingIHttpClientFactory for HTTP clients (never new HttpClient())IHostedService / BackgroundService for background workblazorsignalrgrpcminimal-apis (prefer unless controllers needed)web-apiv10.0.11 is a servicing release rather than a new programming model. It updates OpenAPI to 2.7.5, fixes restoration of expired client-persisted Blazor circuit state, and refreshes servicing dependencies. Keep the existing middleware and endpoint architecture, then rerun focused OpenAPI, interactive-rendering, auth, and startup tests.aspnetcore-10.0 remains the routing entry point for choosing between Blazor, Minimal APIs, controller APIs, SignalR, and gRPC; the refresh does not justify changing an existing app model by itself.csharpvar app = builder.Build(); app.UseExceptionHandler("/error"); // 1. Catch all exceptions app.UseHsts(); // 2. Security headers app.UseHttpsRedirection(); // 3. HTTPS redirect app.UseStaticFiles(); // 4. Serve static files app.UseRouting(); // 5. Route matching app.UseCors(); // 6. CORS policy app.UseAuthentication(); // 7. Who are you? app.UseAuthorization(); // 8. Can you access? app.UseRateLimiter(); // 9. Rate limiting app.UseResponseCaching(); // 10. Response cache app.MapControllers(); // 11. Endpoints
csharppublic class RequestTimingMiddleware { private readonly RequestDelegate _next; private readonly ILogger<RequestTimingMiddleware> _logger; public RequestTimingMiddleware(RequestDelegate next, ILogger<RequestTimingMiddleware> logger) { _next = next; _logger = logger; } public async Task InvokeAsync(HttpContext context) { var sw = Stopwatch.StartNew(); await _next(context); _logger.LogInformation("Request {Path} completed in {Elapsed}ms", context.Request.Path, sw.ElapsedMilliseconds); } }
csharp// appsettings.json { "EmailSettings": { "SmtpServer": "smtp.example.com", "Port": 587 } } // Registration builder.Services.Configure<EmailSettings>( builder.Configuration.GetSection("EmailSettings")); // Usage public class EmailService(IOptions<EmailSettings> options) { private readonly EmailSettings _settings = options.Value; }
csharpbuilder.Configuration .AddJsonFile("appsettings.json", optional: false) .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true) .AddEnvironmentVariables() .AddUserSecrets<Program>(optional: true);
csharpbuilder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = builder.Configuration["Jwt:Issuer"], ValidAudience = builder.Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]!)) }; });
csharpbuilder.Services.AddAuthorization(options => { options.AddPolicy("AdminOnly", policy => policy.RequireRole("Admin")); options.AddPolicy("MinAge18", policy => policy.RequireClaim("Age", "18", "19", "20")); // simplified });
| Anti-Pattern | Why It's Bad | Better Approach | |--------------|--------------|-----------------| | new HttpClient() | Socket exhaustion | IHttpClientFactory | | Sync-over-async (Task.Result) | Thread pool starvation | await properly | | Storing secrets in appsettings.json | Security risk | User Secrets, Key Vault | | Catching all exceptions silently | Hides bugs | Use IExceptionHandler | | async void in middleware | Crashes process | async Task | | Missing HTTPS redirect | Security risk | UseHttpsRedirection() |
UseResponseCompression()UseOutputCache() for .NET 7+Span<T>, poolingOther measured skills in the registry, with their headline benchmark lift.