Drn hosting

From duranserkan/DRN-Project · View interactive version

Drn hosting is an AI agent skill from the GitHub repository duranserkan/DRN-Project. Configure DRN hosts, MFA, API errors, rate limits, Razor endpoints, CSP and TagHelpers.

How to use this skill

Skill file

DRN.Framework.Hosting

Use version-matched references. The [Hosting README][hosting] owns full signatures, examples, and defaults. Example* names are placeholders.

DrnProgramBase Pattern

Derive from DrnProgramBase<TProgram> implementing IDrnProgram and AddServicesAsync. Use public/protected hooks, not internal configurators. DrnProgramActions exposes ApplicationBuilderCreatedAsync and ApplicationValidatedAsync.

Configure Source-Known epoch/minimum before startup or first ID/epoch use. Temporary hosts and SkipValidation never bypass time validation. Temporary apps skip endpoint validation/accessor population, run service validation and ApplicationValidatedAsync, and return without starting. Use explicit DrnDevelopmentSettings test flags and never weaken runtime checks with environment branches (testing).

Razor uses IDE/dotnet watch Hot Reload, not runtime compilation. Execution requires authorization. Framework overview and Utils own config, DI, app data, environment rules, and [HostedService].

Security Features

MFA by Default

MFA applies by default (including role and named-policy endpoints). [AllowAnonymous] allows public access. AuthPolicy.MfaExempt allows authenticated access without MFA.

GDPR & Consent

DrnDefaults withholds non-essential cookies until consent. Apps own script activation, category preferences, and IsEssential (README Cookies and consent).

Swagger And Developer Tool Authorization

Swagger defaults to Development only. Elsewhere, call base in ConfigureSwaggerOptions, set AddSwagger = true, and assign a named AuthorizationPolicy protecting UI, assets, and OpenAPI docs (including custom routes). MFA still applies. Null uses fallback authorization. Blank policy names are invalid.

Swagger UI prefixes require nonempty ASCII letter, digit, hyphen, or underscore segments and reject root mounts. Reserve the UI subtree for Swagger CSP. Disabled UI keeps app policies. Retain base behavior in ConfigureSecurityHeaderPolicyBuilder. README owns AddSwaggerUI, metadata, doc URLs, title defaults, caching, and DrnPageOptions.FaviconUrl.

Page & Endpoint Management

README Source-Known Controllers owns service-backed SourceKnown*Controller (protected Service/Repository, ISourceKnownService<TEntity, TResponse>, virtual CreateEntityAsync). Use installed DRN.Framework.SharedKernel CONVENTIONS.md (Terminology) via version-matched lookup for canonical Domain, Subdomain, project stem, and role stem terms. DRNAUTHORIZATION001 requires named policies. SPA APIs use bearer-only schemes and cookie APIs need antiforgery. Keep resource checks in app code. Disable actions with [NonAction] and omit their accessors (IgnoreApi only hides docs). MVC still discovers eligible public methods on derived controllers.

Return typed EndpointCollection singletons (including generated roots) from ConfigureEndpointCollection and pair with typed PageCollection singletons. Never cache request URLs or auth results statically. EndpointName is a label, not a registered name. Use Path(...) for templates and Url.Endpoint for routing, constraints, encoding, and prefixes.

Hosting ships net10.0 generation via buildTransitive targets (README Automatic hosted accessors owns eligibility, DRNHOSTING002, and Razor rules). Reuse typed singletons and keep Get and route constants handwritten. Controller accessors require ControllerBase. Discovery skips others and explicit mappings report DRNHOSTING001.

Prefer MVC routing or Url.Endpoint(endpoint, values) for APIs. Use ~/ for HTML/HTMX URLs, Url.Content in C#, and Request.ApplicationUrl for configured destinations (such as MFA pages). Preserve validated return URLs. Use ForPage for page identities and ForUrl for URLs (Razor accessors).

IPageUtils.RenderPageAsync supports _ViewStart, layouts, and links for unmatched requests, disposing its DI scope asynchronously on success or failure. parentContext preserves PathBase and nonce without transferring scope ownership.

Error Responses

DRN exceptions retain status (default 500). Flurl keeps 400-499/503/504 and maps other failures to 502. BadHttpRequestException keeps StatusCode (default 400). Other exceptions return 500. Names and inner exceptions never choose status. Preserve cancellation/abort behavior and never replace a started response.

Problem Type precedence: response, scope, status default, about:blank (never changes status). Leave Type unset for routine failures. Explicit types name stable public conditions, never CLR names, routes, or request data.

API 400-599 responses emit Problem Details in every environment with JsonConventions.DefaultOptions (not MVC/HTTP JSON overrides). Matched endpoints use API metadata. Unmatched routes/405s use DrnApiErrorOptions.PathPrefixes (default empty). Preserve auth decisions, headers, cookies, validation, and extensions. requestId is HttpContext.TraceIdentifier. Default instance is PathBase + Path without query. Keep exceptions and fallbacks private/redacted.

ScopeContext.Problem fills missing fields/keys without overriding standard fields or validation. [DisableDrnProblemDetails] opts out of formatting and Swagger error metadata while keeping native responses and auth (README API Failure Responses).

HandleHtmxRequests defaults false. Opt in for HTMX Problem Details (including Razor handlers) while preserving redirects, auth, opt-outs, and custom non-problem bodies. Razor Page() selects HTML. ObjectResult with ValidationProblemDetails(ModelState) selects JSON at 400/422. Use safe messages, exact posted field names, and an empty key for form-level errors without overwriting API keys (README HTMX Partial Requests, browser handling).

DrnPageOptions configures anonymous, non-cacheable 400/404/5xx browser pages independent of app data while preserving status, request reference, prefixes, redaction, existing bodies, Development diagnostics, and unmatched-route fallback auth. Supported API exceptions bypass WriteProductionErrorResponseAsync unless opted out. For access-denied references, use AccessDeniedPageModel and PreserveAccessDeniedRequestId() (README Custom Error Pages owns cookie-event ordering, TempData, and EventsType).

Follow Utils and the profile diagnostic guide. Apps own dynamic classification. SanitizeText does not certify content and runtime names do not redact. Keep private diagnostics out of public errors. Use [DeveloperExceptionPreview] on preview endpoints and DeveloperExceptionAccess.AllowsAsync for links (README Developer Diagnostics and Startup Exception Reports).

Rate Limiting Rules

README Rate Limiting and Telemetry own settings, examples, metrics, and log fields.

TagHelpers

Activate in _ViewImports.cshtml:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, DRN.Framework.Hosting

README Razor TagHelpers owns Vite/SRI, CSP nonces, HTMX CSRF, active links, opt-outs, and script defaults. Buildwww skills own asset layout.

authorized-only/anonymous-only are presence-only markers checking ScopeContext.Authenticated (even "false" enables filtering, omit or use Razor conditions to disable, does not check MFA). policy-only="PolicyName" checks the user with optional policy-resource and fails on invalid policy names. Visibility never inspects linked endpoints or replaces endpoint authorization.

<a asp-page="/User/Login" anonymous-only>Sign In</a>
<button type="button" policy-only="EditDocument" policy-resource="@Model.Document">Edit</button>

Publish Vite manifests with assets. Use DrnStaticFileHeaderOptions for startup header rules (Set, Remove, Override, IfMissing). robots.txt revalidation is enabled by default. README Static Asset Compression owns integrity hashes, Brotli-only entries, and path matching.

Related Skills

[hosting]: https://github.com/duranserkan/DRN-Project/blob/master/DRN.Framework.Hosting/README.md

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.