Skip to content

Routing and Page Classes

Mike Christensen edited this page Aug 28, 2026 · 1 revision

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.

Path mapping

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.

Query-string binding

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:

  • string and char;
  • Guid and DateTime;
  • bool;
  • signed and unsigned integer types;
  • float, double, and decimal;
  • 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.

Custom fallback routes

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.

Status codes and canonical routes

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.

Clone this wiki locally