Argon.Extensions.Hosting 8.4.0
Argon.Extensions.Hosting
Middlewares and extensions for ASP.NET Core applications.
📦 Installation
dotnet add package Argon.Extensions.Hosting
✨ Features
StaticPathBaseMiddleware: Middleware to handle a static path base- Extensions to easily configure middlewares
🚀 Usage
StaticPathBaseMiddleware
This middleware ensures that all requests start with a specified path base. Requests that don't match the path base will receive a 404 response.
using Argon.Extensions.Hosting.Middlewares;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Use a static path base
app.UseStaticPathBase("/api");
app.MapControllers();
app.Run();
What it does
- Validates that incoming requests start with the specified path base
- Adds the path base to
HttpContext.Request.PathBase - Returns 404 for requests that don't match the path base
- Properly strips the path base from the remaining path
Example
With app.UseStaticPathBase("/api"):
- ✅
/api/users→ PathBase:/api, Path:/users - ✅
/api/products/123→ PathBase:/api, Path:/products/123 - ❌
/users→ 404 Not Found
Configuration
var app = builder.Build();
// Configure the static path base
app.UseStaticPathBase("/api/v1");
// Your other middleware
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
📝 API Reference
Extensions
UseStaticPathBase
public static IApplicationBuilder UseStaticPathBase(
this IApplicationBuilder app,
PathString pathBase)
Adds the StaticPathBaseMiddleware to the application pipeline.
Parameters:
app: The application builderpathBase: The path base to extract (must not be empty)
Returns: The application builder for method chaining
Exceptions:
ArgumentNullException: Ifappis nullArgumentException: IfpathBaseis null or empty
🔗 Links
No packages depend on Argon.Extensions.Hosting.
.NET 8.0
- Argon.Extensions.Hosting.Abstractions (>= 8.4.0)