Active Sessions in Business central and kill session

Here I want to show how to check active sessions in Business central.

If the business central is on the cloud, then login to the admin center, open the environment.


If the business central is on-prem, then the below power shell script can be used.

View the sessions:

Get-NAVServerSession -SeverInstance <Name> -Tenant <Tenant-id>

Kill the session:

Remove-NAVServerSession -ServerInstance <Name> -Tenant default -SessionId <Session Id>

The other way to view the sessions by creating a simple extension. This can be used in both on-cloud and on-prem version of business central. Below is the code to create a page.

page 60102 "Active Sessions"
{
    PageType = List;
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "Active Session";
    Editable = false;

    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field("Session ID"; "Session ID")
                {
                    ApplicationArea = all;
                }
                field("User ID"; "User ID")
                {
                    ApplicationArea = All;
                }
                field("Client Type"; "Client Type")
                {
                    ApplicationArea = all;
                }
                field("Login Datetime"; "Login Datetime")
                {
                    ApplicationArea = all;
                }
                field("Server Computer Name"; "Server Computer Name")
                {
                    ApplicationArea = all;
                }
                field("Server Instance Name"; "Server Instance Name")
                {
                    ApplicationArea = all;
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            action("Kill Session")
            {
                Caption = 'Kill Session';
                ApplicationArea = All;
                Image = Delete;

                trigger OnAction()
                begin
                    if Session.IsSessionActive("Session ID") then
                        if StopSession("Session ID") then
                            Message('Session stopped!');
                end;
            }
        }
    }

    var
        myInt: Integer;
}

Comments

Popular posts from this blog

Next object id in VS Code