Skip to content

EsmAccessControlOptions class

namespace: Serenity.Web   assembly: Serenity.Net.Web

Options for the ESM access control (see UseEsmAccessControl), which serves the ES modules and chunks under an esm folder (e.g. /esm/ or /Serenity.Extensions/esm/) only to users who may load an entry point (e.g. a page module) that needs them, using the build.esm-manifest that tsbuild writes next to them.

public class EsmAccessControlOptions

Public Members

name description
EsmAccessControlOptions() The default constructor.
AnonymousPaths { get; set; } Semicolon separated patterns of the entry points (or other files) that anonymous users can load, e.g. the login page. The files that these entry points reach are public too.
DefaultPermission { get; set; } The permission of entry points that do not match any other rule. Default is "?", e.g. logged-in users. Like other permissions, an empty value is invalid and denies access.
Enabled { get; set; } Whether the ESM access control is enabled. Default is false.
MissingManifestAllowedPaths { get; set; } Semicolon separated patterns of the full request paths of esm folders that are served without access control when they have no manifest, whatever MissingManifestPermission is, e.g. /lib/** for the libraries under wwwroot/lib. A pattern is matched against the path of the folder with a trailing slash, e.g. /lib/some-library/esm/.
MissingManifestPermission { get; set; } The permission (or permission expression) required to load the files of an esm folder without a build.esm-manifest, e.g. the folder of a package built with a tsbuild version that does not write the manifest. Default is "*", which serves them without access control, as before. "?" makes such a folder fail safe for anonymous users, and "DENY" serves them to no one. Like other permissions, an empty value is invalid and denies access. Note that any folder named esm is treated as an esm folder, including ones that are not built by tsbuild, like the esm folder of a library copied under wwwroot/lib, so list those in MissingManifestAllowedPaths.
Permissions { get; set; } Optional patterns of entry points mapped to the permission (or permission expression) required to load them, e.g. { "Modules/Administration/**": "Administration:General" }. When a path matches more than one pattern, the longest pattern wins. Empty by default, in which case entry points that are not anonymous use DefaultPermission. Note that a page may load modules of another page, e.g. to open a dialog of another module, which fails for users without the permission of that module.
const SectionKey The default section key in appsettings.json

Remarks

Each file is served if the user has the permission of at least one entry point that reaches it via its imports. The permission of an entry point is, in order:

  1. the Permission if it is a layout module,
  2. "*" (public) if it matches AnonymousPaths,
  3. the permission of the longest matching pattern in Permissions, if any,
  4. DefaultPermission.

So unless Permissions is set, anonymous users only get the anonymous and layout module files, while logged-in users get all of them. A file that is not in the manifest is treated as an entry point of its own. Files of an esm folder without a manifest are served as before, unless MissingManifestPermission says otherwise.

Patterns are semicolon separated globs (*, **, ?), case-insensitive, relative to the esm folder (e.g. Modules/Membership/**), or the full request path if they start with a slash (e.g. /Serenity.Extensions/esm/Modules/Membership/**).

See Also