Configuration Overview
SupermarketWEB uses ASP.NET Core’s configuration system with settings stored inappsettings.json and environment-specific overrides in appsettings.Development.json. Configuration is loaded automatically at application startup in Program.cs.
Database Configuration
Connection String Setup
The database connection is configured inappsettings.json under the ConnectionStrings section:
appsettings.json
Connection String Components
| Component | Value | Description |
|---|---|---|
Data Source | (localdb)\\MSSQLLocalDB | SQL Server instance (LocalDB by default) |
Initial Catalog | SupermarketEF | Database name |
Integrated Security | True | Use Windows authentication |
Connect Timeout | 30 | Connection timeout in seconds |
Encrypt | False | Disable connection encryption |
Configuring for Different Environments
- SQL Server LocalDB (Default)
- SQL Server Express
- SQL Server with Credentials
- Azure SQL Database
Use the default configuration for local development:
Entity Framework Core Configuration
The database context is registered inProgram.cs:
Program.cs
SupermarketContext manages five entity sets:
Products- Product inventoryCategories- Product categoriesCustomers- Customer recordsPayModes- Payment methodsUsers- User accounts
Authentication Configuration
Cookie Authentication Setup
SupermarketWEB uses cookie-based authentication configured inProgram.cs:
Program.cs
Authentication Settings
| Setting | Value | Description |
|---|---|---|
Cookie.Name | MyCookieAuth | Name of the authentication cookie |
LoginPath | /Account/Login | Redirect path for unauthenticated users |
Customizing Authentication
To modify authentication behavior, update the cookie options inProgram.cs:
The authentication system works with the
Users entity in the database. User credentials are validated against the Email and Password fields.Logging Configuration
Log Levels
Logging is configured inappsettings.json:
appsettings.json
Available Log Levels
Trace- Most detailed loggingDebug- Debugging informationInformation- General informational messages (default)Warning- Warning messagesError- Error messagesCritical- Critical failuresNone- Disable logging
Development Logging
Development-specific logging can be configured inappsettings.Development.json:
appsettings.Development.json
Environment-Specific Configuration
Development Environment
Development settings inappsettings.Development.json:
- Detailed error pages
- Developer exception page
- Verbose logging
Production Environment
The application detects production environment and applies different middleware inProgram.cs:
Program.cs
- Generic error handling via
/Errorpage - HTTP Strict Transport Security (HSTS)
- HTTPS redirection
- No detailed errors exposed
Application Settings
Allowed Hosts
Configure allowed host headers inappsettings.json:
HTTPS Configuration
HTTPS is enforced in production through middleware inProgram.cs:
Properties/launchSettings.json.
Middleware Pipeline
The request pipeline is configured inProgram.cs:
Program.cs
- HTTPS Redirection - Redirects HTTP to HTTPS
- Static Files - Serves files from
wwwroot - Routing - Matches requests to endpoints
- Authorization - Validates authentication cookies
- Razor Pages - Executes page handlers
Configuration Best Practices
Use Environment Variables
Store sensitive configuration in environment variables, not in
appsettings.json:Separate Environments
Maintain separate configuration files for each environment:
appsettings.json- Base settingsappsettings.Development.json- Development overridesappsettings.Production.json- Production overrides
Configuration Priority
ASP.NET Core loads configuration in this order (later sources override earlier ones):appsettings.jsonappsettings.{Environment}.json- User Secrets (Development only)
- Environment variables
- Command-line arguments
Next Steps
With your configuration complete, you’re ready to start using SupermarketWEB. Explore the features:- Manage products and inventory
- Organize items by category
- Track customer information
- Configure payment methods
- Secure your application with user authentication