Skip to content

ASP.NET Core ​

Provides the shared ASP.NET Core layer the other web packages build on: one standardized error response shape, exception mapping, request metadata capture, CORS setup, and forwarded-header configuration for a Cloudflare-proxied application.

Every error body shares one shape, whether HttpErrorResponseWriter writes it from middleware and exception handlers or an action returns it as an HttpErrorResult, so a client sees the same envelope wherever the failure came from.

Adopting it is a set of independent registrations followed by one middleware call, so an application can take the error response shape without the exception handlers, or the reverse. Everything beyond that is a helper reached from HttpContext, HttpRequest, or HttpResponse.

Categories ​

  • Configuration — the AllowedOrigins, AllowedHeaders, and AllowedMethods sections the CORS policy is built from.
  • Exceptions — the IExceptionMapper standard your own handler is built on.
  • HTTP Error Messages — the http-error.json files every status description is resolved from.
  • Extensions — registration, middleware, and request helpers.
  • Services — error response writing.
  • Utilities — the Cloudflare edge ranges and the client address header.
  • Types — the MVC result that returns the standardized error body.
  • Records — the response body, session context, and parsed User-Agent.

Quick Example ​

csharp
using AlmightyShogun.AspNet.Core;

builder.Services
    .AddHttpErrorResponseWriter()
    .AddExceptionHandling();

WebApplication app = builder.Build();

app.UseHttpErrorResponses();
csharp
public sealed class OrderNotFoundException(int orderId)
    : Exception($"Order {orderId} was not found.")
{
    public int OrderId { get; } = orderId;
}
csharp
using Microsoft.AspNetCore.Http;
using AlmightyShogun.AspNet.Core;

public sealed class OrderExceptionMapper : IExceptionMapper
{
    public ErrorMapping? Map(Exception exception) => exception switch
    {
        OrderNotFoundException notFound => new ErrorMapping
        {
            StatusCode = StatusCodes.Status404NotFound,
            Code = "order_not_found",
            MessageKey = "orders.not-found",
            MessageParameters = [notFound.OrderId]
        },
        _ => null
    };
}

All packages are released under the MIT License.