Class PageStateMiddleware
- Namespace
- Htmx.Components.State
- Assembly
- Htmx.Components.dll
ASP.NET Core middleware that manages page state across HTTP requests. This middleware automatically loads encrypted page state from request headers, makes it available throughout the request pipeline, and manages state persistence.
public class PageStateMiddleware
- Inheritance
-
PageStateMiddleware
- Inherited Members
- Extension Methods
Constructors
PageStateMiddleware(RequestDelegate)
Initializes a new instance of the PageStateMiddleware with the specified next delegate.
public PageStateMiddleware(RequestDelegate next)
Parameters
next
RequestDelegateThe next middleware delegate in the pipeline
Methods
GetPageState(HttpContext)
Retrieves the page state from the current HTTP context. This method provides access to the page state that was loaded and attached by the middleware.
public static IPageState GetPageState(HttpContext context)
Parameters
context
HttpContextThe HTTP context from which to retrieve the page state
Returns
- IPageState
The page state instance for the current request
Exceptions
- InvalidOperationException
Thrown when page state is not available, typically indicating that the PageStateMiddleware was not properly registered or executed.
InvokeAsync(HttpContext, IPageState)
Processes the HTTP request, loading page state from headers and making it available to the request context. The page state is loaded from the X-Page-State header if present, and attached to the HttpContext for use by subsequent middleware and controllers.
public Task InvokeAsync(HttpContext context, IPageState pageState)
Parameters
context
HttpContextThe HTTP context for the current request
pageState
IPageStateThe page state service injected by dependency injection
Returns
- Task
A task representing the asynchronous middleware operation