Modrich.Web
0.1.0
dotnet add package Modrich.Web --version 0.1.0
NuGet\Install-Package Modrich.Web -Version 0.1.0
<PackageReference Include="Modrich.Web" Version="0.1.0" />
<PackageVersion Include="Modrich.Web" Version="0.1.0" />
<PackageReference Include="Modrich.Web" />
paket add Modrich.Web --version 0.1.0
#r "nuget: Modrich.Web, 0.1.0"
#:package Modrich.Web@0.1.0
#addin nuget:?package=Modrich.Web&version=0.1.0
#tool nuget:?package=Modrich.Web&version=0.1.0
Modrich.Web
Host-side web helpers for Modrich on .NET 10. Sits between the Tier 1 abstractions and the concrete host. Modules do not reference this package.
What's in the box
GlobalExceptionHandlingMiddleware— catches unhandled exceptions and writes a JSON envelope ({ StatusCode, Message }). Maps common exception types:ArgumentException→400KeyNotFoundException→404UnauthorizedAccessException→401- anything else →
500with a generic message
CultureEndpoints.MapCultureEndpoints(endpoints)— registersGET /Culture/Set?culture=fr&redirectUri=/which writes the ASP.NET Core localization cookie and local-redirects back.
Install
dotnet add package Modrich.Web
Usage — JSON exception middleware on /api only
The middleware emits JSON, so wire it on the API branch only — HTML routes should keep the standard exception handler so Blazor can render its own error page.
using Modrich.Web.Middleware;
var app = builder.Build();
app.UseExceptionHandler("/error"); // HTML routes
app.UseHsts();
app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/api"), branch =>
{
branch.UseMiddleware<GlobalExceptionHandlingMiddleware>();
});
app.Run();
Response shape on failure:
{ "StatusCode": 404, "Message": "Order 42 not found." }
Usage — culture switcher
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
using Modrich.Web.Endpoints;
var supported = new[] { "en", "fr", "de" };
builder.Services.Configure<RequestLocalizationOptions>(o =>
{
o.SetDefaultCulture("en")
.AddSupportedCultures(supported)
.AddSupportedUICultures(supported);
});
var app = builder.Build();
app.UseRequestLocalization(app.Services.GetRequiredService<IOptions<RequestLocalizationOptions>>().Value);
app.MapCultureEndpoints(); // GET /Culture/Set?culture=fr&redirectUri=/
app.Run();
A language switcher link:
<a href="/Culture/Set?culture=fr&redirectUri=@Uri.EscapeDataString(currentPath)">Français</a>
The endpoint writes a one-year IsEssential = true, SameSite = Lax cookie via CookieRequestCultureProvider.MakeCookieValue(...), then issues a LocalRedirect back to redirectUri (defaults to /).
Related packages
Modrich.Abstractions/Modrich.Modularity— the host you're configuring most likely uses these.
Versioning
Strict semver. EnablePackageValidation is on.
License
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Modrich.Web:
| Package | Downloads |
|---|---|
|
Modrich.Sdk.Web
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.