aspnet-configuration
Guide for ASP.NET Core configuration with appsettings.json, environment-specific settings, and the options pattern
Best use case
aspnet-configuration is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Guide for ASP.NET Core configuration with appsettings.json, environment-specific settings, and the options pattern
Teams using aspnet-configuration should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/aspnet-configuration/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How aspnet-configuration Compares
| Feature / Agent | aspnet-configuration | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Guide for ASP.NET Core configuration with appsettings.json, environment-specific settings, and the options pattern
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# ASP.NET Core Configuration
This skill provides guidance for **configuration management** in ASP.NET Core applications using appsettings.json, environment-specific settings, user secrets, and the options pattern.
## Table of Contents
1. [Configuration Files](#configuration-files)
2. [Environment-Specific Configuration](#environment-specific-configuration)
3. [Accessing Configuration](#accessing-configuration)
4. [Options Pattern](#options-pattern)
5. [User Secrets](#user-secrets)
6. [Best Practices](#best-practices)
7. [Quick Reference](#quick-reference)
---
## Configuration Files
### appsettings.json
Both projects have appsettings.json:
- `src/ClaudeStack.Web/appsettings.json`
- `src/ClaudeStack.API/appsettings.json`
**Standard structure:**
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
```
### Configuration Hierarchy
ASP.NET Core loads configuration in this order (later sources override earlier):
1. appsettings.json
2. appsettings.{Environment}.json
3. User Secrets (Development only)
4. Environment variables
5. Command-line arguments
---
## Environment-Specific Configuration
### appsettings.Development.json
Overrides appsettings.json in Development environment:
- `src/ClaudeStack.Web/appsettings.Development.json`
- `src/ClaudeStack.API/appsettings.Development.json`
**Example:**
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information"
}
}
}
```
### Determining Environment
**Set via environment variable:**
```bash
# Windows
$env:ASPNETCORE_ENVIRONMENT="Development"
# Linux/macOS
export ASPNETCORE_ENVIRONMENT=Development
```
**Check in code:**
```csharp
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // Only in development
}
```
### Creating Environment-Specific Files
```bash
# Create production settings
# src/ClaudeStack.Web/appsettings.Production.json
```
Automatically loaded when `ASPNETCORE_ENVIRONMENT=Production`.
---
## Accessing Configuration
### IConfiguration Interface
**In Program.cs (Minimal API):**
```csharp
var builder = WebApplication.CreateBuilder(args);
// Access configuration from builder
var connectionString = builder.Configuration["ConnectionStrings:DefaultConnection"];
var app = builder.Build();
// Access configuration in endpoint
app.MapGet("/config", (IConfiguration config) =>
{
var value = config["MySettings:MyValue"];
return value;
});
```
**In MVC Controller:**
```csharp
public class HomeController : Controller
{
private readonly IConfiguration _configuration;
public HomeController(IConfiguration configuration)
{
_configuration = configuration;
}
public IActionResult Index()
{
var value = _configuration["MySettings:MyValue"];
return View();
}
}
```
### Nested Configuration
**appsettings.json:**
```json
{
"Database": {
"ConnectionString": "Server=localhost;Database=MyDb",
"Timeout": 30
}
}
```
**Access:**
```csharp
var connectionString = config["Database:ConnectionString"];
var timeout = config.GetValue<int>("Database:Timeout");
```
---
## Options Pattern
### Strongly-Typed Configuration
**1. Define options class:**
```csharp
public class DatabaseOptions
{
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
```
**2. Bind configuration:**
```csharp
// In Program.cs
builder.Services.Configure<DatabaseOptions>(
builder.Configuration.GetSection("Database"));
```
**3. Use in services/controllers:**
```csharp
public class UserService
{
private readonly DatabaseOptions _options;
public UserService(IOptions<DatabaseOptions> options)
{
_options = options.Value;
}
public void Connect()
{
var conn = _options.ConnectionString;
}
}
```
### IOptions vs IOptionsSnapshot vs IOptionsMonitor
```csharp
IOptions<T> // Singleton, never reloads
IOptionsSnapshot<T> // Scoped, reloads per request
IOptionsMonitor<T> // Singleton, reloads on change
```
**Use IOptions** for most cases.
**Use IOptionsSnapshot** if configuration changes between requests.
**Use IOptionsMonitor** to react to configuration changes in real-time.
---
## User Secrets
### Overview
User Secrets stores sensitive configuration **outside** the project directory. Used in Development only.
**For:**
- API keys
- Connection strings
- Passwords
**Not for:**
- Production secrets (use Azure Key Vault, etc.)
- Non-sensitive settings
### Initialize User Secrets
```bash
cd src/ClaudeStack.Web
dotnet user-secrets init
```
Adds `<UserSecretsId>` to .csproj:
```xml
<PropertyGroup>
<UserSecretsId>guid-here</UserSecretsId>
</PropertyGroup>
```
### Set Secrets
```bash
# Set individual secret
dotnet user-secrets set "ApiKey" "secret-value-123"
# Set nested secret
dotnet user-secrets set "Database:ConnectionString" "Server=..."
# List all secrets
dotnet user-secrets list
# Remove secret
dotnet user-secrets remove "ApiKey"
# Clear all secrets
dotnet user-secrets clear
```
### Access Secrets
Same as regular configuration:
```csharp
var apiKey = builder.Configuration["ApiKey"];
```
**Location:**
- Windows: `%APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets.json`
- Linux/macOS: `~/.microsoft/usersecrets/<user_secrets_id>/secrets.json`
---
## Best Practices
### 1. Never Commit Secrets
```bash
# .gitignore already includes:
appsettings.Development.json # Sometimes
**/secrets.json
```
Use User Secrets for local development secrets.
### 2. Use Options Pattern
**Prefer:**
```csharp
builder.Services.Configure<MyOptions>(
builder.Configuration.GetSection("MySettings"));
```
**Over:**
```csharp
var value = builder.Configuration["MySettings:Value"]; // Weakly-typed
```
### 3. Validate Options
```csharp
builder.Services.AddOptions<DatabaseOptions>()
.Bind(builder.Configuration.GetSection("Database"))
.ValidateDataAnnotations()
.ValidateOnStart();
public class DatabaseOptions
{
[Required]
public string ConnectionString { get; set; }
[Range(1, 300)]
public int Timeout { get; set; }
}
```
### 4. Environment-Specific Settings
```json
// appsettings.json - defaults
{
"Database": {
"ConnectionString": "Server=localhost"
}
}
// appsettings.Production.json - production overrides
{
"Database": {
"ConnectionString": "Server=prod-server"
}
}
```
### 5. Connection Strings
Special section:
```json
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=MyDb"
}
}
```
Access:
```csharp
var connStr = builder.Configuration.GetConnectionString("DefaultConnection");
```
---
## Quick Reference
### Configuration Access
```csharp
// Simple value
config["MyKey"]
// Nested value
config["Section:SubSection:Key"]
// Typed value
config.GetValue<int>("Section:IntKey")
// Connection string
config.GetConnectionString("DefaultConnection")
// Entire section
var section = config.GetSection("MySection")
```
### Options Pattern
```csharp
// Register
builder.Services.Configure<MyOptions>(
builder.Configuration.GetSection("MySection"));
// Use (constructor injection)
public MyService(IOptions<MyOptions> options)
{
var value = options.Value.Property;
}
```
### User Secrets Commands
```bash
dotnet user-secrets init
dotnet user-secrets set "Key" "Value"
dotnet user-secrets list
dotnet user-secrets remove "Key"
dotnet user-secrets clear
```
### Environment Setup
```bash
# Set environment
$env:ASPNETCORE_ENVIRONMENT="Development"
# Check in code
if (app.Environment.IsDevelopment()) { }
if (app.Environment.IsProduction()) { }
```
---
## Related Skills
- **dotnet-minimal-apis**: Using configuration in minimal APIs
- **dotnet-cli-essentials**: Running applications with different environments
---
## Additional Resources
- [Configuration in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/)
- [Options Pattern](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options)
- [User Secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets)
- [Environment Variables](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments)
---
## Version Information
- **ASP.NET Core**: 10.0 RC 2
- **.NET SDK**: 10.0.100-rc.2.25502.107
Configuration system is stable across .NET versions. This project uses .NET 10 RC 2 patterns.Related Skills
azure-appconfiguration-ts
Build applications using Azure App Configuration SDK for JavaScript (@azure/app-configuration). Use when working with configuration settings, feature flags, Key Vault references, dynamic refresh, o...
aspnet-core-advanced
Master advanced ASP.NET Core development including Entity Framework Core, authentication, testing, and enterprise patterns for production applications.
ameba-configuration
Use when configuring Ameba rules and settings for Crystal projects including .ameba.yml setup, rule management, severity levels, and code quality enforcement.
akka-net-aspire-configuration
Configure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integration, and Aspire orchestration patterns.
aceternity-ui-configuration
Specifies that Aceternity UI dependencies should be considered during code generation or modification.
shellcheck-configuration
Master ShellCheck static analysis configuration and usage for shell script quality. Use when setting up linting infrastructure, fixing code issues, or ensuring script portability.
clippy-configuration
Use when configuring Clippy for Rust projects with TOML config, lint groups, attributes, and workspace setup.
n8n-node-configuration
Operation-aware node configuration guidance. Use when configuring nodes, understanding property dependencies, determining required fields, choosing between get_node detail levels, or learning commo...
mtls-configuration
Configure mutual TLS (mTLS) for zero-trust service-to-service communication. Use when implementing zero-trust networking, certificate management, or securing internal service communication.
langchain4j-vector-stores-configuration
Configure LangChain4J vector stores for RAG applications. Use when building semantic search, integrating vector databases (PostgreSQL/pgvector, Pinecone, MongoDB, Milvus, Neo4j), implementing embedding storage/retrieval, setting up hybrid search, or optimizing vector database performance for production AI applications.
aspnet-core
Guidelines for ASP.NET Core web development covering API design, authentication, caching, and best practices
aspnet-core-fundamentals
Master ASP.NET Core fundamentals including C#, project structure, routing, middleware, and basic API development. Essential skills for all ASP.NET Core developers.