-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Mike Christensen edited this page Aug 28, 2026
·
2 revisions
This guide creates a minimal ASP.NET Core application whose /hello URL maps to a Hello page class.
- A current .NET SDK and ASP.NET Core application
- The
KitchenPC.Imppackage
dotnet new web --name HelloImp
cd HelloImp
dotnet add package KitchenPC.ImpThis installs the latest stable package. Pin an explicit version in applications that require reproducible restores.
Replace Program.cs with:
using Imp;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseStaticFiles();
app.UseImp(config => config
.PageAssembly(typeof(Program).Assembly)
.RootPageNamespace("HelloImp.Pages"));
app.Run();Imp is terminal middleware: it handles the request and does not invoke middleware registered after it. Put exception handling, authentication, authorization, and static-file handling before UseImp.
Add Pages/Hello.cs:
using System.Text.Encodings.Web;
using Imp;
namespace HelloImp.Pages;
public sealed class Hello : BasePage
{
public string Name { get; set; } = "World";
public override Task Render(HttpResponse response)
{
var name = HtmlEncoder.Default.Encode(Name);
return response.WriteAsync($"<h1>Hello, {name}!</h1>");
}
}Run the application:
dotnet run-
/hellomaps toHelloImp.Pages.Hello. -
/hello?Name=MikebindsNameand rendersHello, Mike!. -
/maps to a class namedHelloImp.Pages.Default.
Always encode request-derived text before writing HTML. Query binding converts values; it does not perform output encoding or validation.
public sealed class NotFound : BasePage
{
public override void PreRender(HttpResponse response) =>
response.StatusCode = StatusCodes.Status404NotFound;
public override Task Render(HttpResponse response) =>
response.WriteAsync("<h1>Page not found</h1>");
}Register it:
.NotFoundPageType<HelloImp.Pages.NotFound>()- Move HTML into embedded templates and layouts.
- Learn the exact request lifecycle.
- Run the complete Todo sample.
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