Skip to main content

Application Configuration

The Dev Showcase application is configured in Program.cs using ASP.NET Core’s minimal hosting model.

Service Registration

AddControllersWithViews

builder.Services.AddControllersWithViews();
Registers services required for MVC controllers with view support. This includes:
  • Controller activation and model binding
  • View rendering engine (Razor)
  • JSON formatters for API responses
  • Default MVC conventions and filters

Middleware Pipeline

The middleware pipeline is configured in the following order:

1. Exception Handling (Production Only)

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}
Environment
IWebHostEnvironment
Environment-specific behavior. In non-development environments:
  • Unhandled exceptions redirect to /Home/Error
  • HSTS (HTTP Strict Transport Security) is enabled

2. HTTPS Redirection

app.UseHttpsRedirection();
Redirects HTTP requests to HTTPS automatically.

3. Routing

app.UseRouting();
Enables endpoint routing middleware.

4. Authorization

app.UseAuthorization();
Enables authorization middleware (currently not configured with specific policies).

5. Static Assets

app.MapStaticAssets();
Maps static asset endpoints for serving CSS, JavaScript, images, and other static files.

Route Configuration

The application defines several route patterns:

Root Redirect

app.MapGet("/", context =>
{
    context.Response.Redirect("/dataScience", permanent: false);
    return Task.CompletedTask;
});
Redirects the root URL (/) to the default profile (/dataScience).

Language-Only Redirect

app.MapGet("/{lang:regex(^(es|en)$)}", (string lang, HttpContext context) =>
{
    context.Response.Redirect($"/{lang}/dataScience", permanent: false);
    return Task.CompletedTask;
});
lang
string
Language code constrained by regex to es (Spanish) or en (English). Redirects to /{lang}/dataScience.

Profile with Language Route

app.MapControllerRoute(
    name: "profilesWithLang",
    pattern: "{lang}/{profile}",
    defaults: new { controller = "Home", action = "Profile" },
    constraints: new
    {
        lang = "^(es|en)$",
        profile = @"^(dataScience|webDev|dataAnalyst|DataAnalysis)$"
    });
lang
string
required
Language code: es or en
profile
string
required
Profile identifier: dataScience, webDev, dataAnalyst, or DataAnalysis
Maps to: HomeController.Profile(string profile)

Profile without Language Route

app.MapControllerRoute(
    name: "profiles",
    pattern: "{profile}",
    defaults: new { controller = "Home", action = "Profile" },
    constraints: new { profile = @"^(dataScience|webDev|dataAnalyst|DataAnalysis)$" });
profile
string
required
Profile identifier: dataScience, webDev, dataAnalyst, or DataAnalysis
Maps to: HomeController.Profile(string profile)

Default MVC Route

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=HomePage}/{id?}")
    .WithStaticAssets();
Standard MVC route pattern with:
  • Default controller: Home
  • Default action: HomePage
  • Optional id parameter
  • Static assets support enabled

Environment-Specific Behavior

Development

  • Detailed exception pages are shown
  • No HSTS enforcement
  • Developer-friendly error messages

Production

  • Custom error page at /Home/Error
  • HSTS enabled for secure connections
  • Generic error messages to prevent information disclosure

Build docs developers (and LLMs) love