Contribute to Docs Contribute to Docs

Startup Options

When you add Piranha to your Startup.cs as described in Application Setup, all of the available middleware and routing components are added by default. While this is perfect for most green field websites you may need to control the exactly what parts of the pipeline that are active when integrating Piranha into an existing application.

AddRazorRuntimeCompilation

services.AddPiranha(options =>
{
    options.AddRazorRuntimeCompilation = true;
});

Enables runtime compilation for Razor .cshtml files. This is useful for development environments so that you don't have to restart the application every time you update a view or page. The default value of this property is false as you shouldn't have runtime compilation enabled in production.

Routing

The following options is available when calling UseCms() to configure how the application listens to incoming requests.

UseAliasRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UseAliasRouting = false;
    });
});

If alias routing should be enabled in the middleware pipeline. The default value is true.

UseArchiveRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UseArchiveRouting = false;
    });
});

If archive routing should be enabled in the middleware pipeline. The default value is true.

UsePageRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UsePageRouting = false;
    });
});

If page routing should be enabled in the middleware pipeline. The default value is true.

UsePostRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UsePostRouting = false;
    });
});

If post routing should be enabled in the middleware pipeline. The default value is true.

UseSitemapRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UseSitemapRouting = false;
    });
});

If the middleware should listen for and handle incoming requests to /sitemap.xml. The default value is true.

UseSiteRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UseSiteRouting = false;
    });
});

If site routing should be enabled in the middleware pipeline. This can be disabled if you only have one site in your application. The default value is true.

UseStartpageRouting

services.AddPiranha(options =>
{
    options.UseCms(o =>
    {
        o.UseStartpageRouting = false;
    });
});

If start page routing should be enabled in the middleware pipeline. The default value is true.

Manager options

The following options is available when calling UseManager() to configure the application.

JSON Options

services.AddPiranha(options =>
{
    options.UseManager(o =>
    {
        o.JsonOptions => 
        {
            ...
        };
    });
});

This action can be used if you need to modify the Newtonsoft JSON options used by the manager when serializing data through its API's. Please note that the following values can't be changed as they are needed by the manager application.

SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;

XSRF Cookie Name

services.AddPiranha(options =>
{
    options.UseManager(o =>
    {
        o.XsrfCookieName = "MY_ANTIFORGERY_COOKIE";
    });
});

The manager interface uses header based anti forgery validation to protect against CSRF attacks. This option configure the name of the cookie that the manager uses to communicate the token to the client. The default value is XSRF-REQUEST-TOKEN.

XSRF Header Name

services.AddPiranha(options =>
{
    options.UseManager(o =>
    {
        o.XsrfHeaderName = "MY_ANTIFORGERY_TOKEN";
    });
});

Sets the name of the header the manager will use to pass along the anti forgery token to its API. If you already use header based anti forgery protection in your application you should change this option to the name you're currently using to prevent conflicts. The default value is X-XSRF-TOKEN.

Using appsettings.json

Using the options pattern in ASP.NET Core you can also easily configure the routing options in your appsettings.json. Please note that this is just an example and your appsettings.json can have any structure you want.

appsettings.json

{
  "Piranha": {
    "Routing": {
      "UseSiteRouting": false
    }
  }
}

Startup.cs

public Startup(IConfiguration configuration)
{
    _config = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddPiranha(options =>
    {
        options.UseCms(o =>
            _config.GetSection("Piranha")
                ?.GetSection("Routing")
                ?.Bind(o));
    });
}