Skip to main content

appSettings.json files

The installed application is configured in the appsettings.json file of the Server project. This configuration is used by the server, and part of it is transmitted to the Blazor WebAssembly client.

warning

The only keys usable on the client side are those of the App section and its subsections. Do not place secrets in App, since these values are exposed to the browser.

File format​

{
"ConnectionStrings": {
"DefaultConnection": "DataSource=app.db"
},
"MySampleSection": {
"MySampleKey": "Value of my key"
},
"App": {
"Name": "LagoonDev",
"EnvironmentName": "DEV",
"EnvironmentColor": "#0045BC",
"MyAppClientCustomKey": "My value",
"About": {
"AdditionalInformation": [
{
"Label": "My label:",
"Description": "Lorem ipsum",
"Uri": "https://example.com"
}
]
},
"ClientLogger": {
"SyncErrorDelay": 1800,
"MaxResendErrorAttempts": 10,
"MaxLocalErrorsCount": 200
}
}
}

Using the configuration on the server side​

Inject IConfiguration into the services, controllers, or server classes that need to read the configuration.

MyService.cs
public class MyService
{
private readonly IConfiguration _configuration;

public MyService(IConfiguration configuration)
{
_configuration = configuration;
}

public string GetConfiguredValue()
{
// Reads an application value with a default value if the key is missing.
return _configuration.GetValue("MySampleSection:MySampleKey", "MyDefaultValue");
}
}

The indexer syntax is also available: configuration["MySampleSection:MySampleKey"].

Using the configuration on the client side​

On the client side, only keys under App are available.

MyClientService.cs
public class MyClientService
{
private readonly IConfiguration _configuration;

public MyClientService(IConfiguration configuration)
{
_configuration = configuration;
}

public string GetClientValue()
{
// The key must belong to the App section to be transmitted to the client.
return _configuration.GetValue("App:MyAppClientCustomKey", "MyDefaultValue");
}
}

Common Lagoon sections​

SectionUsage
ConnectionStringsConnection strings used by the application DbContext.
AutoUpdateDatabaseIndicates whether the server applies migrations at startup when Main.OnStartAsync reads it.
LoggingASP.NET Core logging levels.
AppApplication information available on both the server and client sides.
LagoonServer-side framework settings: public URL, logging, SMTP, CSP, OpenID certificate, etc.

App section​

KeyDescriptionDefault
NameApplication name.Application root name.
EnvironmentNameShort environment name displayed if EnvironmentDisplayName is absent, for example PROD or DEV.Not set.
EnvironmentDisplayNameEnvironment name displayed; if absent, Lagoon uses EnvironmentName.EnvironmentName.
EnvironmentColorColor associated with the current environment.Not set.
PostLogoutUriURL called after logout.Not set.
PostLogoutModeMode used to call PostLogoutUri: Navigation or XHR.Navigation.
About:AdditionalInformationAdditional information displayed on the About page.No entry.
ClientLogger:SyncErrorDelayClient error synchronization delay, in seconds.1800.
ClientLogger:MaxResendErrorAttemptsMaximum number of client error resend attempts.10.
ClientLogger:MaxLocalErrorsCountMaximum number of client errors kept locally.200.

PostLogoutMode accepts two behaviors:

ValueEffect
NavigationNavigates to the PostLogoutUri URL after logout.
XHRCalls PostLogoutUri asynchronously without waiting for the result.

Lagoon section​

The following keys are used by Lagoon modules when the corresponding features are enabled.

KeyUsage
PublicUrlPublic URL of the application. It is notably used to build the CSP and public URLs.
RemotePublicUrlValue transmitted to the client to check consistency with <base href>.
ConfigPageTokenToken protecting the server configuration page.
AutoUpdateDatabaseIndicates whether the framework applies migrations at startup.
Authentication:OpendIdCertificateName or path of the OpenID certificate used by the server.
Authentication:CertificateBase64OpenID certificate as a string: <certificate>.<private key> in base64, or base64 of a pfx. Takes precedence over files.
DefaultLoggersRetention of pre-registered ASP.NET Core loggers.
LightConsoleLoggerSimplified console logging.
FileLoggerLagoon file logging.
SmtpServer-side email sending.
CSPContent Security Policy generated by Lagoon.
EulaFilesHTML EULA/terms-of-use files used by shared mode.
ChromiumPathPath to the Chromium instance used by Lagoon.PDF when installed.

Environments​

  • appsettings.json contains the base configuration.
  • appsettings.Development.json overrides this configuration in development.
  • Production secrets must be provided by the runtime environment or by the host's secure configuration, not versioned in plain text.