-
Notifications
You must be signed in to change notification settings - Fork 0
Routing and Page Classes
Imp derives a fully qualified .NET type from the URL path. It does not use route tables or controller/action conventions.
Given:
.RootPageNamespace("MySite.Pages")| Request | Page type |
|---|---|
/ |
MySite.Pages.Default |
/about |
MySite.Pages.About |
/account/profile |
MySite.Pages.Account.Profile |
Path-to-type lookup is case-insensitive. The page must derive from BasePage and live in the assembly selected by PageAssembly.
Imp assigns query values to public writable properties whose names match exactly:
public sealed class Search : BasePage
{
public string Query { get; set; }
public int Page { get; set; } = 1;
public SortMode Sort { get; set; } = SortMode.Relevance;
}/search?Query=imp&Page=2&Sort=Newest binds all three. Property names and enum values are case-sensitive during binding. Unrecognized names and invalid values are ignored, leaving the existing property value.
Supported property types are:
-
stringandchar; -
GuidandDateTime; -
bool; - signed and unsigned integer types;
-
float,double, anddecimal; - enums;
- nullable versions of the supported value types.
Parsing uses the process culture for numeric and date values. For public URLs where invariant formatting matters, accept a string and validate/parse it explicitly.
Binding is not validation. Check ranges, allowed values, required fields, and authorization inside application code. Encode values at the HTML output boundary.
OnNotFound handles routes that cannot be represented by a fixed namespace, such as /articles/my-post or /todo/{guid}:
app.UseImp(config => config
.PageAssembly(typeof(Program).Assembly)
.RootPageNamespace("MySite.Pages")
.OnNotFound(request =>
{
if (request.Path.StartsWithSegments("/articles"))
return typeof(MySite.Pages.ArticlePermalink);
return null;
})
.NotFoundPageType<MySite.Pages.NotFound>());The callback is synchronous and returns a page Type, not an instance. Imp still creates the returned type through dependency injection and assigns its Request. Parse the slug or ID from Request.Path in the page.
Return null when the callback does not recognize the path. Imp then uses NotFoundPageType, falling back to its built-in not-found page if that type cannot be constructed.
Custom route pages should set 404 when a syntactically valid route points to a missing record. If several paths can reach the same content, redirect or emit canonical metadata at the application layer. Imp does not perform URL generation, canonicalization, or trailing-slash policy.
Imp is MIT licensed. See the source and Todo sample on GitHub.
Imp
Templates
Application integration
- Forms and antiforgery
- Dependency injection
- Authentication and secure pages
- Static assets and CDN paths
- Configuration reference
Help and reference