HomeController
TheHomeController is the main controller responsible for handling profile routing, language switching, and error pages.
Namespace: dev_showcase.Controllers
Base Class: Microsoft.AspNetCore.Mvc.Controller
Profile Action
Handles profile page requests for different developer profiles.The profile identifier. Must be one of the valid profile values.
Valid Profile Values
The controller validates profile names against a case-insensitive whitelist:dataScience- Data Science profilewebDev- Web Development profiledataAnalyst- Data Analyst profileDataAnalysis- Data Analysis profile
Returns
- IActionResult: Returns
View("HomePage")with the profile set inViewData["Profile"]if valid - NotFoundResult: Returns 404 if the profile is not in the valid profiles list
Route Mapping
This action is mapped through two route patterns defined inProgram.cs:
- With Language:
/{lang}/{profile}- e.g.,/en/dataScience - Without Language:
/{profile}- e.g.,/dataScience
SetLanguage Action
Sets the user’s language preference via a cookie.The language code to set. Defaults to “es” if not provided or null.
Cookie Configuration
The method sets a cookie namedlang with the following options:
- Expires: 1 year from the current UTC time
- IsEssential:
true- cookie is essential for the application to function - Default Value: “es” (Spanish) if
langis null or not provided
Returns
- OkResult: Returns HTTP 200 status code
HTTP Method
POST - This endpoint only accepts POST requestsError Action
Displays the error page with diagnostic information.Response Caching
The error action is decorated with caching attributes to prevent caching:- Duration: 0 seconds
- Location:
ResponseCacheLocation.None - NoStore:
true
Returns
- ViewResult: Returns the Error view with an
ErrorViewModelinstance - The
RequestIdis populated with either:Activity.Current?.Idif availableHttpContext.TraceIdentifieras fallback
Route
In production environments, this is configured as the exception handler route:/Home/Error