Contribute to Docs Contribute to Docs

Model Loader

The Model Loader is part of the package Piranha.AspNetCore and is intended to be used when building integrated web applications with ASP.NET.

The Model Loader is a scoped service that simplifies model loading for Pages & Posts for the current request. It has support for loading unpublished content and drafts if the current user has access to it. It can be used both from your .cshtml views or pages, or from your backend Controllers.

Registering The Service

The Model Loader is registered automatically when calling UseCms in ConfigureServices.

services.AddPiranha(options =>
{
    options.UseCms();

    ...
});

Methods

GetPage
Task<T> GetPageAsync<T>(Guid id, ClaimsPrincipal user, bool draft = false) where T : PageBase;

Gets the page with the given id as the specified type. If draft is set to true the given user is checked for the correct claims for previewing pages.

If the page has policies specified on it that the user need to view it these will be checked as well. If the current user doesn't have access to the page an UnauthorizedAccessException is thrown.

GetPost
Task<T> GetPostAsync<T>(Guid id, ClaimsPrincipal user, bool draft = false) where T : PostBase;

Gets the post with the given id as the specified type. If draft is set to true the given user is checked for the correct claims for previewing posts.

If the post has policies specified on it that the user need to view it these will be checked as well. If the current user doesn't have access to the post an UnauthorizedAccessException is thrown.