BlockOperation()
ts
BlockOperation(): void;Calling this method at any point in a script instructs the server (the virtual site's "worker process") to block the next operation requested by the client, regardless of what that operation is.
IMPORTANT
BlockOperation() does not terminate the session or disconnect the client. It only blocks the next operation (such as a file upload, directory listing, or authentication attempt) that would otherwise be allowed. The session remains active, and the client may attempt further operations.
This is commonly used in event-handlers to enforce security policies, prevent unwanted actions, or implement custom business logic. For example:
- Block a directory listing (in the
OnDirListevent-handler) - Block a file upload (in the
BeforeFileUploadevent-handler) - Block a specific authentication attempt (in the
OnAuthRequestevent-handler) - ...and so on
Example
Assume this is triggered by a BeforeFileUpload event-handler:
ts
{
if (Session) {
// Block uploads of files that have ".pdf" extension
if (ExtractExt(Session.GetRelPath()) === ".pdf") {
Session.BlockOperation();
Log("Blocked file upload for banned user.");
}
} else {
Log('Session object is not available.');
}
}