IceCoffee.AspNetCore 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package IceCoffee.AspNetCore --version 2.0.0
                    
NuGet\Install-Package IceCoffee.AspNetCore -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IceCoffee.AspNetCore" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IceCoffee.AspNetCore" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IceCoffee.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IceCoffee.AspNetCore --version 2.0.0
                    
#r "nuget: IceCoffee.AspNetCore, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IceCoffee.AspNetCore@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IceCoffee.AspNetCore&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IceCoffee.AspNetCore&version=2.0.0
                    
Install as a Cake Tool

IceCoffee.AspNetCore

A lightweight, opinionated ASP.NET Core library that provides a StartupBase class and a set of utilities to bootstrap web API applications with sensible defaults — authentication, Swagger (NSwag), CORS, Serilog structured logging, Mapster object mapping, and response caching — all driven by configuration flags.


Target Frameworks

Framework Version
.NET 8.0, 10.0

Features

Feature Description
StartupBase Opinionated base class for ConfigureServices / Configure. Derive and override only what you need.
Global authentication Every controller endpoint requires an authenticated user by default (AuthorizeFilter).
HTTP Basic Auth Optional idunno.Authentication.Basic-powered Basic Auth, fully configured from appsettings.json.
Swagger / OpenAPI NSwag document generation with Basic Auth security definition, controller-summary-based tag descriptions, and PathBase-aware server URL.
CORS Configurable allowed origins; falls back to AllowAnyOrigin when none are specified.
Serilog Structured logging with ReadFrom.Configuration, optional per-request HTTP logging, and an ArchiveHooks helper for automatic log file compression and 180-day retention.
Mapster FastExpressionCompiler-powered global type adapter with built-in string?JsonNode? mappings.
Response caching Pre-configured with case-insensitive paths, 64 MB max body, and 200 MB total size limit.
DateTimeConverter Forces all DateTime values in JSON responses to the yyyy-MM-ddTHH:mm:ss.fffZ format.
Forwarded headers Trusts all forwarded headers and clears known-network/proxy restrictions for reverse-proxy deployments.
Static files Serves wwwroot when present; applies no-cache headers to index.html to prevent stale SPA shells.
HttpContextExtension Extension methods for remote IP, request culture, and absolute URL reconstruction.

Installation

dotnet add package IceCoffee.AspNetCore

Quick Start

1. Derive from StartupBase

using IceCoffee.AspNetCore;

public class Startup : StartupBase
{
    public Startup(WebApplicationBuilder builder) : base(builder) { }

    public override void ConfigureServices(IServiceCollection services)
    {
        base.ConfigureServices(services); // apply all defaults

        // Register your own services here
        services.AddScoped<IMyService, MyService>();
    }

    public override void Configure(WebApplication app, IServiceProvider services)
    {
        // Add your own middleware / endpoints here
    }
}

2. Wire it up in Program.cs

var builder = WebApplication.CreateBuilder(args);

var startup = new Startup(builder);
startup.ConfigureServices(builder.Services);

var app = builder.Build();
startup.Configure(app, app.Services);

app.Run();

Configuration Reference

All flags are read from appsettings.json (or any registered IConfiguration provider).

{
  // Enable Serilog per-request HTTP logging
  "EnableRequestLog": true,

  // Mount the application under a sub-path (e.g. "/api")
  "PathBase": "",

  // Expose NSwag Swagger UI at /swagger
  "EnableSwagger": true,

  // Enable the CORS policy
  "EnableCors": true,

  // Allowed origins for CORS; omit or leave empty to allow any origin
  "AllowedOrigins": [ "https://example.com" ],

  // HTTP Basic Authentication
  "BasicAuthOptions": {
    "Enabled": false,
    "Realm": "Basic Authentication",
    "UserName": "<set via secrets / env var>",
    "Password": "<set via secrets / env var>"
  },

  // Serilog configuration (standard Serilog.AspNetCore schema)
  "Serilog": {
    "MinimumLevel": { "Default": "Information" },
    "WriteTo": [
      {
        "Name": "File",
        "Args": {
          "path": "logs/log-.txt",
          "rollingInterval": "Day",
          "hooks": "IceCoffee.AspNetCore.SerilogHooks::ArchiveHooks, IceCoffee.AspNetCore"
        }
      }
    ]
  }
}

Security note: Never store BasicAuthOptions:UserName or BasicAuthOptions:Password in source-controlled appsettings.json. Use .NET user-secrets in development and environment variables / a secrets manager in production.


Utilities

SerilogHooks.ArchiveHooks

A pre-built ArchiveHooks instance (180-day retention, smallest compression) ready to attach to a Serilog rolling-file sink.

DateTimeConverter

Registered globally in ConfigureServices. Serialises DateTime as yyyy-MM-ddTHH:mm:ss.fffZ; deserialises any ISO 8601 string.

HttpContextExtension

Method Description
GetRemoteIpAddress() Client IP after forwarded-headers resolution.
GetCulture() BCP 47 culture tag resolved by the localisation middleware.
GetCurrentUri() Fully qualified absolute URL of the current request.

License

Copyright © 2026 IceCoffee. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 111 4/29/2026
2.0.0 99 4/29/2026
1.2.2 313 7/18/2024
1.2.1 293 2/18/2024
1.2.0 285 2/2/2024
1.1.5 298 11/15/2023
1.1.4 215 9/21/2023
1.1.3 240 9/15/2023
1.1.2 203 9/14/2023
1.1.1 258 7/18/2023
1.1.0 250 7/13/2023
1.0.3.23 282 6/13/2023
Loading failed